【发布时间】:2020-05-10 05:06:20
【问题描述】:
代码:
E,=plt.plot(bl,semullts_mean,color='b',marker='o',label='Sequential')
F,=plt.plot(bl,semulltr_mean,color='c',marker='o',label='Random')
legend3 = plt.legend(handles=[E,F]) #(CORRECT)
K,=pylab.errorbar(bl,semullts_mean,yerr=semulltr_std,ecolor='m',color='g',marker='o',label='Sequential')
L,=pylab.errorbar(x=bl,y=semulltr_mean,yerr=semulltr_std,ecolor='y',color='g',marker='o',label='Random') #(ERROR)
这是我的代码中显示的错误日志
ValueError Traceback (most recent call last)
<ipython-input-8-21aefb184d1d> in <module>()
190 #semulbwr_std=np.reshape(semulbwr_std, (semulbwr_std.shape[0], ))
191
--> 192
K,=pylab.errorbar(bl,semullts_mean,yerr=semulltr_std,ecolor='m',color='g',marker='o',label='Sequential')
193
L,=pylab.errorbar(x=bl,y=semulltr_mean,yerr=semulltr_std,ecolor='y',color='g',marker='o',label='Random')
194 legend5 = pylab.legend(handles=[K,L])
#(ERROR LOGS)
ValueError: too many values to unpack (expected 1)
原来如此。我不知道为什么我不能使用可用于创建绘图的变量创建错误栏 前两行是正确的,它能够生成情节。但是当我使用相同的变量来生成错误栏时。它不断发布此错误。而且没找到好办法解决
我正在使用 matplotlib。 bl、semulltr_mean 和 semulltr_std 等是具有 11 个元素的列表。例如,[1,2,3,4,5,6,7,8,9,10,11]。它们都含有相同数量的元素。不知道是什么原因造成的这个问题
【问题讨论】:
-
我已经使用 numpy 将其转换为 numpy.array。但它似乎不起作用
-
顺便说一句,pylab模块的使用是not recommended,你应该改用
matplotlib.pyplot.errorbar() -
这两个模块有什么区别?
-
在提供的链接中有解释。 pylab 应该可以帮助人们从 MATLAB 过渡,但我猜维护者认为它不再需要
标签: python-3.x matplotlib error-handling valueerror