Skip to main content
 首页 » 编程设计

python之如何在 Windrose.py 中插入我自己的值

2025年04月02日13bhlsheji

我发现了 this模块效果很好,我喜欢输出。 我正在尝试更改随机输入的值,此处:

ws = random(500)*6 
wd = random(500)*360 

来自 this reference我们了解到

This example uses randoms values for wind speed and direction(ws and wd variables). In situation, these variables are loaded with reals values (1-D array), from a database or directly from a text file (see the “load” facility from the matplotlib.pylab interface for that).

使用我的代码,我创建了两个列表:

angles = [v1, v2, v3...] # values that replace wd 
length = [v1, v2, v3...] # values that replace ws 

这些是我迄今为止尝试过但行不通的方法:

wd=np.array(angles) 
wx=np.array(length) 
 
wd=np.asarray(angles) 
... 
wd=np.fromiter(angles) 
... 
All give the error : TypeError: 'list' object is not callable 

为了确保我确实有数组:

a = np.array(angles) 
print type(a) 
<type 'numpy.ndarray'> 
print a.ndim 
1 

我也试过直接用在线程 here. 中找到的值替换,结果相同(列表不可调用) 所以我用给定的数组替换 random(),但 Qgis 仍然返回“列表”错误。
我错过了什么?

请您参考如下方法:

试试这个例子并检查列表 angles 和 length 中的值,它们必须是 float 或整数:

from windrose import WindroseAxes 
from matplotlib import pyplot as plt 
import matplotlib.cm as cm 
from numpy.random import random 
from numpy import arange, array 
 
angles = [10.,20,40.,100.] 
length = [1.,2.,3.,10] 
 
ws = array(length) 
wd = array(angles) 
 
fig = plt.figure(figsize=(8, 8), dpi=80, facecolor='w', edgecolor='w') 
rect = [0.1, 0.1, 0.8, 0.8] 
ax = WindroseAxes(fig, rect, axisbg='w') 
fig.add_axes(ax) 
 
ax.bar(wd, ws, normed=True, opening=0.8, edgecolor='white') 
plt.show()