如何在 Matplotlib (python) 中隐藏轴和网格线

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45148704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 16:45:23  来源:igfitidea点击:

How to hide axes and gridlines in Matplotlib (python)

pythonmatplotlib

提问by Alex Santelle

I would like to be able to hide the axes and gridlines on a 3D matplotlib graph. I want to do this because when zooming in and out the image gets pretty nasty. I'm not sure what code to include here but this is what I use to create the graph.

我希望能够隐藏 3D matplotlib 图形上的轴和网格线。我想这样做是因为在放大和缩小图像时会变得非常讨厌。我不确定要在此处包含哪些代码,但这是我用来创建图形的代码。

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.view_init(30, -90)
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
plt.xlim(0,pL)
plt.ylim(0,pW)
ax.set_aspect("equal")

plt.show()

This is an example of the plot that I am looking at:
This is an example of the plot that I am looking at

这是我正在查看的情节示例:
这是我正在查看的情节示例

采纳答案by azalea

# Hide grid lines
ax.grid(False)

# Hide axes ticks
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])

Note, you need matplotlib>=1.2 for set_zticks()to work.

请注意,您需要 matplotlib>=1.2set_zticks()才能工作。

回答by Johnnyh101

Turn the axes off with:

关闭轴:

plt.axis('off')

And gridlines with:

和网格线:

plt.grid(b=None)