我正在尝试绘制错误栏:
plt.errorbar(np.array(x_axis), np.array(y_axis), yerr=(np.array(y_bot), np.array(y_top)), linestyle='None', marker='^')
但它引发了一个错误:
plt.errorbar(np.array(x_axis), np.array(y_axis), yerr=(np.array(y_bot), np.array(y_top)), linestyle='None', marker='^')
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/pyplot.py", line 2747, in errorbar
errorevery=errorevery, capthick=capthick, **kwargs)
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/axes/_axes.py", line 2792, in errorbar
barcols.append(self.vlines(xo, lo, uo, **lines_kw))
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/axes/_axes.py", line 1067, in vlines
for thisx, (thisymin, thisymax) in zip(x, Y)]
ValueError: too many values to unpack
x_axis,y_axis,y_bot,x_bot是长度为4的1D数组。
答案 0 :(得分:2)
以下对我来说很好:
import numpy as np
import matplotlib.pyplot as plt
x_axis = range(4)
y_axis = range(4)
y_bot = range(4)
y_top = range(4)
plt.errorbar(np.array(x_axis), np.array(y_axis), yerr=(np.array(y_bot), np.array(y_top)), linestyle='None', marker='^')
您想要验证数组