首页 > 解决方案 > 风玫瑰蟒的自定义缩放

问题描述

我正在尝试比较 python 中的风玫瑰,但这很困难,因为我无法弄清楚如何在所有地块上制作相同的比例。其他人在这里问了同样的问题Custom percent scale used by windrose.py 但没有得到回答。

示例代码:

from windrose import WindroseAxes
import numpy as np
import matplotlib.pyplot as plt

wind_dir = np.array([30,45,90,43,180])
wind_sd = np.arange(1,wind_dir.shape[0]+1)
bins_range = np.arange(1,6,1) # this sets the legend scale
fig,ax = plt.subplots()
ax = WindroseAxes.from_ax()

下面的 bin_range 设置了条形的比例,但我需要更改 y 轴频率比例,以便可以将其与具有不同数据的其他风玫瑰进行比较。

ax.bar(wind_dir,wind_sd,normed=True,bins=bins_range) 

这个 set_ylim 似乎确实有效,但 yaxis 刻度没有改变

ax.set_ylim(0,50)

下面这个 set_ticks 行没有做任何事情,我不知道为什么

ax.yaxis.set_ticks(np.arange(0,50,10))

ax.set_legend()
plt.show()

标签: pythonmatplotlibpolar-coordinates

解决方案


from windrose import WindroseAxes
import numpy as np
import matplotlib.pyplot as plt

wind_dir = np.array([30,45,90,43,180])
wind_sd = np.arange(1,wind_dir.shape[0]+1)
bins_range = np.arange(1,6,1) # this sets the legend scale

ax = WindroseAxes.from_ax()
ax.bar(wind_dir,wind_sd,normed=True,bins=bins_range)
ax.set_yticks(np.arange(10, 60, step=10))
ax.set_yticklabels(np.arange(10, 60, step=10))
plt.show()

在此处输入图像描述


推荐阅读