如何在matplotlib 3d中隐藏轴? [英] How can I hide the axes in matplotlib 3d?

查看:56
本文介绍了如何在matplotlib 3d中隐藏轴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不显示轴的情况下制作3D图?

How can I make a 3D plot without showing the axes?

在绘制3d图时,Matplotlib不仅绘制x,y和z轴,还在x-y,y-z和x-z平面上绘制浅灰色网格.我想绘制一个自由浮动"的 3D 图,没有这些元素.

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.

我尝试过的东西:

# 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)

推荐答案

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:

好吧,看起来3d轴的隐藏是在v1.0版本之后(但在我开始使用mplot3d之前)添加的一项功能.此补丁应在不干扰现有功能的情况下启用基本功能.要隐藏轴,您必须将私有成员_axis3don"设置为 False,如下所示:

Ok, looks like the hiding of the 3d axes was a feature added after the v1.0 release (but before I started working on mplot3d). This patch should enable the basic feature without interfering with existing functions. To hide the axes, you would have to set the private member "_axis3don" to False, like so:

ax = plt.gca(projection='3d')ax._axis3don =假

ax = plt.gca(projection='3d') ax._axis3don = False

如果你这样做,那么你现在就会得到你想要的,并且你的代码在升级时仍然与mplot3d兼容(尽管首选方法是调用set_axis_on()或set_axis_off()).

If you do it this way, then you will get what you want now, and your code will still be compatible with mplot3d when you upgrade (although the preferred method would be to call set_axis_on() or set_axis_off()).

希望能帮到你!

本根

这篇关于如何在matplotlib 3d中隐藏轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆