Matplotlib:在 3d 图中显示 [英] Matplotlib: imshow in 3d plot

查看:32
本文介绍了Matplotlib:在 3d 图中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的图中,取自 matplotlib 的图库,contourf 用于在 3d 绘图下方创建一个 2d 绘图.我的问题是,是否可以使用 imshow 来做同样的事情?我希望二维图中的颜色更平滑.

In the plot below, taken from matplotlib's gallery, contourf is used to create a 2d plot beneath the 3d one. My question is, is it possible to use imshow to do the same thing? I would like the colors in the 2d plot to be smoother.

制作 2d 绘图似乎是可能的,因为 contourf 接受 zdir 参数,而我看过而 imshow 没有.这表明这是不可能的,但为什么不呢?pcolor 也可以完成工作,有可能吗?

Making the 2d plot seems to be possible because contourf accepts a zdir argument, while I've looked and imshow doesn't. That suggests that it isn't possible, but why not? pcolor would also get the job done, is it possible with that?

推荐答案

只需为轮廓指定 levels= 选项,例如

Just specify the levels= option for the contourf, e.g.

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt,numpy as np
plt.clf()
fig = plt.figure(1)
ax = fig.gca(projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
cset = ax.contourf(X, Y, Z, zdir='z', offset=-100,
        levels=np.linspace(-100,100,1200),cmap=plt.cm.jet)
cset = ax.contourf(X, Y, Z, zdir='x', offset=-40, cmap=plt.cm.jet)
cset = ax.contourf(X, Y, Z, zdir='y', offset=40, cmap=plt.cm.jet)
ax.set_xlabel('X')
ax.set_xlim(-40, 40)
ax.set_ylabel('Y')
ax.set_ylim(-40, 40)
ax.set_zlabel('Z')
ax.set_zlim(-100, 100)    
plt.show()

这篇关于Matplotlib:在 3d 图中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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