Skip to main content
 首页 » 编程设计

python之Python 中网格数据的 PolarColor map 绘图

2024年10月17日34lonelyxmas

我想绘制网格数据的彩色 map ,极坐标形式的网格。在数据中,r 的范围从 1 到 2,theta 的范围从 0 到 360。我想要这样的 map :

我是这样设计的

#x1 of shape(12,) 
#y1 0f shape(36,1) 
#z of shape(36,12) 
fig=plt.figure()   
ax=fig.add_subplot(111) #Output Figure 1 
#ax=fig.add_subplot(111,polar='True') #Output Figure 2 
ax=fig.add_subplot(111) 
ax.pcolor(y1,x1,z) 
plt.show() 

输出:

知道如何绘制上图吗?我还尝试将 r、theta 转换为 x、y,然后我得到了 r<1 范围内的彩色图,这是我不想要的。

请您参考如下方法:

正如指出的那样here , pcolormesh() 对此很有用。

import matplotlib.pyplot as plt 
import numpy as np 
 
theta = np.linspace(0, 2*np.pi, 36) 
r = np.linspace(1, 2, 12) 
 
R, THETA = np.meshgrid(r, theta) 
Z = np.sin(THETA) * R 
 
plt.subplot(111, projection='polar') 
plt.pcolormesh(THETA, R, Z) 
plt.gca().set_rmin(0.0) 
 
plt.show() 

output figure