简体   繁体   English

Python:Matplotlib Surface_plot

[英]Python: Matplotlib Surface_plot

I'm trying to Plot a high resolution surface_plot, but I would also really like some nice grid lines on top of it. 我正在尝试绘制一个高分辨率的surface_plot,但我也非常喜欢它上面的一些漂亮的网格线。 If i use the gridlines in the same argument 如果我在同一个参数中使用网格线

ax.plot_surface(x_itp, y_itp, z_itp, rstride=1, cstride=1, facecolors=facecolors, linewidth=0.1)

I get a LOT of grid lines. 我得到了很多网格线。 If I, on the other hand, set "rstride" and "cstride" to higher values, my sphere will become ugly. 另一方面,如果我将“rstride”和“cstride”设置为更高的值,我的球体将变得丑陋。

I then tried to smash a 然后我试图粉碎一个

ax.plot_wireframe(x_itp, y_itp, z_itp, rstride=3, cstride=3)

in afterwards, but it just lies on top of the colored sphere.. meaning that I can see the backside of the wireframe and then the surface_plot behind it all. 之后,它只是位于彩色球体的顶部..这意味着我可以看到线框的背面,然后是它背后的surface_plot。

Have anyone tried this? 有人试过吗?

Another option was to use "Basemap" which can create a nice grid, but then I will have to adapt my colored surface to that.?! 另一个选择是使用“底图”,它可以创建一个漂亮的网格,但然后我将不得不调整我的彩色表面。

My plot looks like this: 我的情节看起来像这样: surface_plot

If I add edges to the map with a higher "rstride" and "cstride" then it looks like this: 如果我使用更高的“rstride”和“cstride”向地图添加边缘,那么它看起来像这样:

在此输入图像描述

code : 代码:

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

I want to show the \\theta and \\phi angles around the sphere.. maybe with 30 degrees apart. 我想在球体周围显示\\ theta和\\ phi角度..可能相隔30度。

Cheers! 干杯! Morten 莫滕

It looks like you may need to use basemap. 看起来您可能需要使用底图。 With plot_surface() you can either have high resolution plot or low resolution with good grid on top. 使用plot_surface(),您可以使用高分辨率绘图或低分辨率,顶部有良好的网格。 But not both. 但不是两个。 I just made a simple basemap with contour plot. 我刚刚用等高线图制作了一个简单的底图。 I think you can do easily apply pcolor on it. 我认为你可以轻松地在它上面应用pcolor。 Just do not draw continent and country boundary. 只是不要绘制大陆和国家边界。 Then, you have a nice sphere which gives more control. 然后,你有一个很好的球体,可以提供更多的控制。 After making your plot, you can easily add grid on it. 制作绘图后,您可以轻松地在其上添加网格。

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

使用底图在球体上的等高线图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM