问题描述
我正在尝试使用我的数据绘制一个误差线图. X是9个元素的ndarray. Y和Yerr是9x5 ndarray.当我打电话时:
I'm trying to make an errorbar plot with my data. X is a 9 element ndarray. Y and Yerr are 9x5 ndarrays. When I call:
matplotlib.pyplot.errorbar(X, Y, Yerr)
我收到ValueError:"yerr必须是标量,与y相同,或2xN."
I get a ValueError: "yerr must be a scalar, the same dimensions as y, or 2xN."
但是Y.shape == Yerr.shape
是True.
我在带有Spyder 2.3.8和Python 3.5.1的64位Windows 7上运行. Matplotlib是最新的.我已经安装了Visual Studio 2015的Visual C ++ Redistributable.
I'm running on 64 bit Windows 7 with Spyder 2.3.8 and Python 3.5.1. Matplotlib is up to date. I've installed Visual C++ Redistributable for Visual Studio 2015.
有什么想法吗?
一些数据.
X=numpy.array([1,2,3])
Y=numpy.array([[1,5,2],[3,6,4],[9,3,7]])
Yerr=numpy.ones_like(Y)
推荐答案
也许文档的"y维度"实际上是1xN ...
Maybe by "dimension of y" the docs actually meant 1xN...
无论如何,这可能有效:
Anyway, this could work:
for y, yerr in zip(Y, Yerr):
matplotlib.pyplot.errorbar(X, y, yerr)
这篇关于matplotlib.pyplot.errorbar抛出错误,它不应该吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!