Pregunta

I can remove the tick labels with:

ax.axes.get_yaxis().set_visible(False)

But that removes the ticks as well. I want to preserve the ticks.

¿Fue útil?

Solución

Just use a NullFormatter

ax = plt.gca()
ax.yaxis.set_major_formatter(matplotlib.ticker.NullFormatter())
plt.draw()

Otros consejos

+1 for @tcaswell answer, I guess that's the standard way to do so. But it has the drawback that the formatter is now missing, and when you move the mouse on your plot you do not get the coordinates of the point the mouse is pointing to.

This is a nice feature I usually rely on, especially because the "data cursor" tool (link) present in Matlab is missing in Matplotlib by default (see mpldatacursor for a plugin with similar features). In Matplotlib I use to hover on a point with the mouse, and read the 'live' coordinates provided by the Formatter.

To turn off the labels without killing the formatter you can use

plt.setp(ax.get_yticklabels(), visible=False)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top