绘制 matplotlib errorbars 给出 AssertionError assert vertices.ndim == 2
Plotting matplotlib errorbars gives AssertionError assert vertices.ndim == 2
我有两个 100x1 数组,我正在互相策划。我可以很容易地绘制它们并获得预期的结果,但是,当我尝试向图中添加任何类型的错误栏时,我收到错误消息
User/lib/python2.7/site-packages/matplotlib/path.py", line 147, in__init__
assert vertices.ndim == 2
AssertionError
我的基本代码是:
xe = numpy.ones((100,1))
pyplot.figure()
pyplot.scatter(frac_K,frac_en)
pyplot.errorbar(frac_K,frac_en, xerr = xe, yerr =xe, linestyle = 'none')
pyplot.show()
frac_K 和 frac_en 在脚本的前面定义为 100x1 个数组。即
print frac_K
[[-0. ]
[-0.00180161]
[-0.00452353]
[-0.00815248]
[-0.01267089]
... etc.
任何关于我哪里出错的指导都将不胜感激。
使用 numpy.ones((100,1))
,您将创建一个二维数组(尺寸为 100 x 1)。您可以在 xe
上调用 call .flatten()
将其转换为一维数组,或者将其创建为一维数组。
xe = numpy.ones((100,1)).flatten()
或...
xe = numpy.ones(100)
这实际上正是 assert vertices.ndim == 2
告诉您的内容,尽管是以一种稍微隐晦的方式。例如
>>> xe = numpy.ones((100,1))
>>> xe.ndim
2
>>> xe = numpy.ones(100)
>>> xe.ndim
1
属性ndim
是"number of dimensions"的缩写。
我有两个 100x1 数组,我正在互相策划。我可以很容易地绘制它们并获得预期的结果,但是,当我尝试向图中添加任何类型的错误栏时,我收到错误消息
User/lib/python2.7/site-packages/matplotlib/path.py", line 147, in__init__
assert vertices.ndim == 2
AssertionError
我的基本代码是:
xe = numpy.ones((100,1))
pyplot.figure()
pyplot.scatter(frac_K,frac_en)
pyplot.errorbar(frac_K,frac_en, xerr = xe, yerr =xe, linestyle = 'none')
pyplot.show()
frac_K 和 frac_en 在脚本的前面定义为 100x1 个数组。即
print frac_K
[[-0. ]
[-0.00180161]
[-0.00452353]
[-0.00815248]
[-0.01267089]
... etc.
任何关于我哪里出错的指导都将不胜感激。
使用 numpy.ones((100,1))
,您将创建一个二维数组(尺寸为 100 x 1)。您可以在 xe
上调用 call .flatten()
将其转换为一维数组,或者将其创建为一维数组。
xe = numpy.ones((100,1)).flatten()
或...
xe = numpy.ones(100)
这实际上正是 assert vertices.ndim == 2
告诉您的内容,尽管是以一种稍微隐晦的方式。例如
>>> xe = numpy.ones((100,1))
>>> xe.ndim
2
>>> xe = numpy.ones(100)
>>> xe.ndim
1
属性ndim
是"number of dimensions"的缩写。