如何隐藏 3d 绘图的轴
如何在不显示轴的情况下绘制 3D 绘图?
绘制 3D 图时,Matplotlib 不仅绘制 x、y 和 z 轴,还在 xy、yz 和 xz 平面上绘制浅灰色网格。我想绘制一个“自由浮动”的 3D 绘图,没有这些元素。
我尝试过的东西:
# Doesn't work; this hides the plot, not the axes
my_3d_axes.set_visible(False)
# Doesn't do anything. Also, there's no get_zaxis() function.
my_3d_axes.get_xaxis().set_visible(False)
my_3d_axes.get_yaxis().set_visible(False)
How can I make a 3D plot without showing the axes?
When plotting a 3d plot, Matplotlib not only draws the x, y, and z axes, it draws light gray grids on the x-y, y-z, and x-z planes. I would like to draw a "free-floating" 3D plot, with none of these elements.
Stuff I've tried:
# Doesn't work; this hides the plot, not the axes
my_3d_axes.set_visible(False)
# Doesn't do anything. Also, there's no get_zaxis() function.
my_3d_axes.get_xaxis().set_visible(False)
my_3d_axes.get_yaxis().set_visible(False)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Ben Root 提供了一个补丁来修复 1.0.1 的这个问题。它可以作为此主题的最后一封电子邮件的附件找到。引用本的话:
Ben Root provided a patch that fixes this for 1.0.1. It can be found as an attachment to the last email of this thread. To quote Ben:
ax.set_axis_off()
只是为了提供 https://stackoverflow.com/a/7363931/895245
输出:
不带
ax.set_axis_off()
它看起来像:但是,您会注意到,这会在图形周围产生过大的空白边距,因为它只是隐藏轴但不会更改视图框。我尝试了
bbox_inches='tight'
和 它不像在 2D 中那样有帮助。如何解决这个问题:删除 Axes3d (matplotlib) 中的空格已测试matplotlib==3.2.2。
ax.set_axis_off()
Just to provide a concrete and direct example of what was mentioned at https://stackoverflow.com/a/7363931/895245
Output:
Without
ax.set_axis_off()
it would look like:You will notice however that this produces an excessively large whitespace margin around the figure as it simply hides the axes but does not change the viewbox. I tried
bbox_inches='tight'
and it did not help as it does in 2D. How to solve that at: Remove white spaces in Axes3d (matplotlib)Tested on matplotlib==3.2.2.