In Python matplotlib how to show a ticklabel without a tick?
Oct 13, 3:27pm
To keep the tick labels but hide the tick marks themselves, set the tick length to zero:
python
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [1, 4, 2])
# Hide tick marks but keep labels
ax.tick_params(axis='both', length=0) # or 'x' / 'y' only
plt.show()
Alternative approaches:
python
# Per-tick, by making the tick line invisible
for tick in ax.get_xticklines():
tick.set_visible(False)
# Or hide ticks but then re-add labels manually
ax.set_xticks([]) # removes both ticks AND labels — not what you want
ax.set_xticks([1, 2, 3])
ax.set_xticklabels(['a', 'b', 'c'])
ax.tick_params(length=0)
The cleanest option is generally ax.tick_params(length=0), which removes the marks while leaving the labels untouched (spacing and formatting stay identical).
Oct 13, 3:27pm
This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.