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

标签 python matplotlib qgis

我发现了 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 仍然返回“列表”错误。
我错过了什么?

最佳答案

试试这个例子并检查列表 angleslength 中的值,它们必须是 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()

enter image description here

关于python - 如何在 Windrose.py 中插入我自己的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37751107/

相关文章:

python - 找出两次 Nose 测试之间差异的好方法是什么?

python - Matplotlib 添加默认水印

d3.js - 在 D3 v4 中渲染 GeoJson 文件无法正确缩放

python - Qgis:IndexError:列表索引超出范围

python - Pip 安装但找不到模块

python - 如何在 matplotlib 中为我的热图使用预制颜色图?

python - 如何加载文件并创建无限保存文件?

python - 如何从列表元素中删除\n?

python - Matplotlib 获取横条边缘的顶部和底部坐标

python - PyQT5 QGIS 对话框交互