Matplotlib:3D 曲面图关闭背景但保留轴 [英] Matplotlib: 3D surface plot turn off background but keep axes

查看:76
本文介绍了Matplotlib:3D 曲面图关闭背景但保留轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个显示轴但不显示轴之间的面的 3D 曲面图.我发现如何使用 ax.set_axis_off() 关闭轴和面.有没有机会只关闭那些面孔,或者让它们变得透明?(在第一张图片中,如果您仔细观察,您可以看到面孔)

I want to do a 3D surface plot that shows axes but does not show the faces that are between the axes. What I found is how to turn off axes as well as the faces using ax.set_axis_off(). Is there any chance to turn off only those faces, or to make them transparent? (In the first picture you can see the faces if you look closely)

提前致谢!

推荐答案

你不能关闭窗格",但你可以改变它们的颜色,从而使它们透明.

You cannot "turn the panes off", but you can change their color and thereby make them transparent.

ax.xaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))

完整代码:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_xlabel("x"); ax.set_ylabel("y"); ax.set_zlabel("z")

x = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(x,x)
Z = np.sin(np.sqrt(X**2 + Y**2))

# make the panes transparent
ax.xaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))
ax.yaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))
ax.zaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))
# make the grid lines transparent
ax.xaxis._axinfo["grid"]['color'] =  (1,1,1,0)
ax.yaxis._axinfo["grid"]['color'] =  (1,1,1,0)
ax.zaxis._axinfo["grid"]['color'] =  (1,1,1,0)

surf = ax.plot_surface(X, Y, Z, cmap=plt.cm.coolwarm,
                   linewidth=0, antialiased=False)

fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()

这篇关于Matplotlib:3D 曲面图关闭背景但保留轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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