In Python matplotlib in additions to ticks with labels, how to show a given ticklabel without a tick?
Oct 13, 3:29pm
In matplotlib, the tick mark and its label are separate objects, so you can hide the little line while keeping the text. A few ways:
Hide all tick marks on an axis (labels stay):
python
ax.tick_params(axis='x', length=0) # or width=0
Hide the mark of one specific tick:
python
tick = ax.xaxis.get_major_ticks()[2] # e.g. 3rd major tick
tick.tick1line.set_visible(False) # the inward line
tick.tick2line.set_visible(False) # the outward line (top axis)
Or style only the ticks you want, e.g. mark only some:
python
for i, tick in enumerate(ax.xaxis.get_major_ticks()):
if i != 0: # keep the mark only on the first tick
tick.tick1line.set_visible(False)
tick.tick2line.set_visible(False)
Note: if the tick is at a spine position, also consider that the spine itself can look like a tick — hide it with ax.spines['bottom'].set_visible(False) if needed.
Oct 13, 3:29pm
This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.