Ticks on a plot, how to get rid of them?

Ticks on a plot, how to get rid of them? - briefly

Use ax.set_xticks([]) and ax.set_yticks([]) or ax.tick_params(bottom=False, left=False, labelbottom=False, labelleft=False) to suppress all tick marks and labels on a Matplotlib plot.

Ticks on a plot, how to get rid of them? - in detail

Removing tick marks from a figure requires explicit commands that alter the axis configuration. In Matplotlib, the most direct method is to clear the tick locations:

ax.set_xticks([])
ax.set_yticks([])

Alternatively, the tick_params function can suppress the visual elements while preserving the underlying scale:

ax.tick_params(bottom=False, top=False, left=False, right=False,
 labelbottom=False, labelleft=False)

Both approaches eliminate the numeric labels and the small lines that denote positions. If only the labels are unwanted, keep the tick lines by setting labelbottom=False and labelleft=False while leaving bottom and left true.

Seaborn plots inherit Matplotlib’s axis objects, so the same commands apply after the plot call:

sns.lineplot(data=df)
plt.gca().set_xticks([])
plt.gca().set_yticks([])

For Plotly, hide ticks through layout adjustments:

fig.update_xaxes(showticklabels=False, ticks="")
fig.update_yaxes(showticklabels=False, ticks="")

The showticklabels flag removes the numbers, and ticks="" removes the short lines.

In Bokeh, use the axis.visible property or set tick label format to an empty string:

p.xaxis.visible = False
p.yaxis.visible = False
# or
p.xaxis.major_label_text_font_size = '0pt'
p.yaxis.major_label_text_font_size = '0pt'

When creating subplots, apply the same settings to each axis object individually, ensuring consistent appearance across the entire figure.

If a figure contains multiple axes, iterate over them:

for ax in fig.get_axes():
 ax.set_xticks([])
 ax.set_yticks([])

The iteration guarantees that no residual tick marks remain on any subplot.

In summary, suppressing tick marks involves either clearing tick positions, disabling label rendering, or removing the tick lines through axis properties. The exact syntax varies by visualization library, but the principle—directly modifying axis attributes—remains consistent.