Python: Matplotlib表面绘图

9
我正在尝试绘制高分辨率的曲面图,但我也希望在其上有一些漂亮的网格线。如果我在相同的参数中使用网格线。
ax.plot_surface(x_itp, y_itp, z_itp, rstride=1, cstride=1, facecolors=facecolors, linewidth=0.1)

我得到了很多的网格线。另一方面,如果我将“rstride”和“cstride”设置为更高的值,我的球体会变得丑陋。
然后我试图压缩一个

(此处可能有遗漏或错误,请根据上下文理解)
ax.plot_wireframe(x_itp, y_itp, z_itp, rstride=3, cstride=3)

在后面,但它只是位于有色球体的顶部..这意味着我可以看到线框模型的背面,然后是所有背后的表面绘图。有人试过这个吗?另一个选择是使用"Basemap",它可以创建一个漂亮的网格,但是我将不得不适应那个彩色的表面吗?!我的图表看起来像这样:surface_plot如果我用更高的"rstride"和"cstride"添加地图边缘,那么它看起来像这样:

enter image description here

代码:
norm = plt.Normalize()
facecolors = plt.cm.jet(norm(d_itp))

# surface plot 
fig, ax = plt.subplots(1, 1, subplot_kw={'projection':'3d', 'aspect':'equal'})
ax.hold(True)
surf = ax.plot_surface(x_itp, y_itp, z_itp, rstride=4, cstride=4, facecolors=facecolors)
surf.set_edgecolors("black")

我想展示球体周围的θ和φ角度.. 可以每30度展示一次。
祝好! Morten

你会发布你的图表吗? - Hun
1个回答

4

看起来你可能需要使用basemap。使用plot_surface()函数,你可以得到高分辨率的图像或者低分辨率但是带有良好的网格线。但是不能同时拥有两者。我刚刚做了一个简单的basemap和等高线图。我认为你可以很容易地在其上应用pcolor。只需不绘制大陆和国家边界,那么你就会得到一个漂亮的球体,从而获得更多控制权。在制作完你的图之后,你可以很容易地添加网格线。

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np

map = Basemap(projection='ortho',lat_0=45,lon_0=-150) 
map.drawmapboundary(fill_color='aquamarine')
map.drawmeridians(np.arange(0,360,30)) # grid every 30 deg
map.drawparallels(np.arange(-90,90,30))

nlats = 73; nlons = 145; delta = 2.*np.pi/(nlons-1)
lats = (0.5*np.pi-delta*np.indices((nlats,nlons))[0,:,:])
lons = (delta*np.indices((nlats,nlons))[1,:,:])
wave = 0.6*(np.sin(2.*lats)**6*np.cos(4.*lons))
mean = 0.5*np.cos(2.*lats)*((np.sin(2.*lats))**2 + 2.)

x, y = map(lons*180./np.pi, lats*180./np.pi) # projection from lat, lon to sphere
cs = map.contour(x,y,wave+mean,15,linewidths=1.5) # contour data. You can use pcolor() for your project
plt.title('test1')
plt.show()

contour plot on sphere using basemap


这可能不完全是您想要的。但我只是给您提供了一种新的可能性。您可以独立控制图形的分辨率和网格间隔。 - Hun

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接