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.

有帮助吗?

解决方案

Just use a NullFormatter

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

其他提示

+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)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top