What to use to eradicate ticks on a plot? - briefly
Clear the tick marks by setting empty tick lists, for example ax.set_xticks([]); ax.set_yticks([])
, or disable them with plt.tick_params(bottom=False, left=False, labelbottom=False, labelleft=False)
. This removes both the marks and any associated labels.
What to use to eradicate ticks on a plot? - in detail
Removing unwanted tick marks and labels from a graph requires direct manipulation of the axis properties provided by the plotting library. The following approaches apply to the most common environments.
In matplotlib (Python), axis ticks are controlled through the Axes
object. To hide all ticks, call ax.tick_params(bottom=False, top=False, left=False, right=False)
. To suppress only the labels while keeping the tick lines, use ax.set_xticklabels([])
and ax.set_yticklabels([])
. For complete removal of both lines and labels, combine the two commands or set the tick locations to an empty list with ax.set_xticks([])
and ax.set_yticks([])
.
In seaborn, which builds on matplotlib, the same tick_params
and set_xticks
/set_yticks
methods work because the underlying Axes
object is accessible via ax = sns.plot(... )
. Additionally, seaborn’s despine
function can remove the top and right spines and optionally hide the remaining ticks: sns.despine(trim=True, ax=ax)
.
In ggplot2 (R), ticks are part of the theme system. Use theme(axis.ticks = element_blank())
to eliminate tick marks while preserving axis lines. To also remove the tick labels, add theme(axis.text = element_blank())
. If only one axis should be cleared, specify axis.ticks.x
or axis.ticks.y
accordingly.
Base R graphics allow direct control through axis
arguments. Setting axes=FALSE
in the initial plot call suppresses all axes, then redraw only the desired components with axis(1, labels=FALSE, tick=FALSE)
for a specific side. Alternatively, box()
draws a surrounding rectangle without ticks.
In Plotly (Python or R), tick visibility is managed via layout settings. For Python, assign fig.update_xaxes(showticklabels=False, ticks='')
and fig.update_yaxes(showticklabels=False, ticks='')
. In R, use layout(xaxis = list(showticklabels = FALSE, ticks = ""))
.
When working with Bokeh, the Axis
objects expose a visible
attribute. Set p.xaxis.visible = False
and p.yaxis.visible = False
to hide both axes entirely, or adjust p.xaxis.major_tick_line_color = None
to remove only the tick lines.
Summary of commands:
- Matplotlib:
ax.tick_params(..., bottom=False, ...)
,ax.set_xticks([])
,ax.set_yticks([])
- Seaborn: same as Matplotlib, plus
sns.despine(trim=True)
- ggplot2:
theme(axis.ticks = element_blank())
,theme(axis.text = element_blank())
- Base R:
plot(..., axes=FALSE)
,axis(1, labels=FALSE, tick=FALSE)
- Plotly:
fig.update_xaxes(showticklabels=False, ticks='')
- Bokeh:
p.xaxis.visible = False
,p.xaxis.major_tick_line_color = None
Select the method that matches the plotting library in use, apply the appropriate function or theme element, and the unwanted tick marks will disappear.