In matplotlib how to hide tick grid line, but keep displaying tick label?
Oct 13, 3:32pm

Use grid(False) on the axis — tick labels are controlled separately from grid lines, so disabling the grid leaves the labels alone:

python
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 5, 1])

ax.grid(False)  # hides grid lines, tick labels stay visible

plt.show()

A few related cases:

Hide the tick marks (the small lines on the axis), but keep labels:

python
ax.tick_params(length=0)  # or ax.tick_params(axis='both', which='both', length=0)

Hide grid lines globally:

python
plt.grid(False)
# or in style: plt.rcParams['axes.grid'] = False

Remove only the ticks, keep both labels and spine:

python
ax.xaxis.set_ticks_position('none')
ax.yaxis.set_ticks_position('none')

Note: grid lines only show if they were enabled (via plt.grid(), ax.grid(), or a style like ggplot). If you're seeing lines you can't remove with grid(False), they're likely the axis spines — remove those with ax.spines['top'].set_visible(False), etc.

Oct 13, 3:32pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Vibe can make mistakes. Check answers. Learn more