雷达图库

2024-09-29 21:59:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在努力改变我正在绘制的风玫瑰图的基线。所以,径向轴上的零点不是在中心而是在基线上。 我知道bottom参数,但当我使用它时,径向记号0保持在中心。你知道吗

我希望它看起来像什么(“0”到达“平静”边界的边缘) enter image description here

我得到的(0仍然在中间,但是所有的条都被移动) enter image description here

我的代码(data2d数组是1年每小时风向的数组):

dir_ticks = np.arange(0,360,22.5)
a = data2d[:,4:6].astype(np.float)
winds_dir = data2d[:,5].astype(np.float)
N_i = []
from0to3_i = []
from0to5_i = []
from0to7_i  = []
from0to9_i  = []

All_probs = len(winds_dir)

for dir_i in dir_ticks:
    N_i += [len(np.where(a[:,1]==dir_i)[0])]
    N = np.where(a[:,1]==dir_i)
    from0to3_i += [len(np.where(np.logical_and(a[N,0]>=0, a[N,0]<3))[0])]
    from0to5_i += [len(np.where(a[N,0]<5)[0])]
    from0to7_i += [len(np.where(a[N,0]<7)[0])]
    from0to9_i += [len(np.where(a[N,0]<9)[0])]


fig = plt.figure(figsize=(5, 5.5), dpi=80, facecolor='w', edgecolor='w')

ax=plt.subplot(111,projection='polar')
ax.set_theta_direction(-1)
ax.set_theta_offset(np.pi/2)
N=16
N_i = np.asarray(N_i)
from0to9_i = np.asarray(from0to9_i)
from0to7_i = np.asarray(from0to7_i)
from0to5_i = np.asarray(from0to5_i)
from0to3_i = np.asarray(from0to3_i)


bottom =5

width = 2*np.pi/(N)-np.pi/(3*N)
b0 = plt.bar(dir_ticks/180*np.pi,N_i/All_probs*100 ,width=width, bottom = bottom, color='#c60000',edgecolor='white')
b1 = plt.bar(dir_ticks/180*np.pi,from0to9_i/All_probs*100,width=width,bottom = bottom, color='y',edgecolor='white')
b2 = plt.bar(dir_ticks/180*np.pi,from0to7_i/All_probs*100,width=width,bottom = bottom,color='g',edgecolor='white')
b3 = plt.bar(dir_ticks/180*np.pi,from0to5_i/All_probs*100,width=width,bottom = bottom, color='c',edgecolor='white')
b4 = plt.bar(dir_ticks/180*np.pi,from0to3_i/All_probs*100,width=width,bottom = bottom, color='b',edgecolor='white')
ax.legend((b4[0],b3[0],b2[0],b1[0],b0[0]),('<3 m/s','3-5 m/s','5-7 m/s','7-9 m/s','>9 m/s'),loc=(0.84,0.91))
plt.yticks(np.arange(3,np.amax(N_i/All_probs*100),3),["%.1f%%" % x for x in np.arange(3,np.amax(N_i/All_probs*100),3)])
ax.set_xticks(theta)
ax.set_xticklabels(['N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW'])
plt.tight_layout()
plt.savefig(datafolder + "windrose.png")

Tags: lendirnppipltallaxwhere

热门问题