Python 绘制matplotlib errorbars会给出AssertionError assert顶点。ndim==2

Python 绘制matplotlib errorbars会给出AssertionError assert顶点。ndim==2,python,matplotlib,Python,Matplotlib,我有两个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.fig

我有两个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数组。i、 e

    print frac_K
    [[-0.        ]
    [-0.00180161]
    [-0.00452353]
    [-0.00815248]
    [-0.01267089]
    ... etc.
如果您能提供任何有关我出错的指导,我们将不胜感激。

使用
numpy.ones((100,1))
您正在创建一个二维阵列(一个尺寸为100 x 1的阵列)。您可以在
xe
上调用call
.flant()
将其转换为1D数组,也可以将其创建为1D数组

xe = numpy.ones((100,1)).flatten()
或者

这实际上正是
assert vertices.ndim==2
告诉您的,尽管有点神秘。e、 g

>>> xe = numpy.ones((100,1))
>>> xe.ndim
2

>>> xe = numpy.ones(100)
>>> xe.ndim
1
属性
ndim
是“尺寸数”的缩写

>>> xe = numpy.ones((100,1))
>>> xe.ndim
2

>>> xe = numpy.ones(100)
>>> xe.ndim
1