首页 文章

Python:ValueError:x和y必须具有相同的第一个维度

提问于
浏览
-1

我正在运行Python 2.7并且我一直在使用它

ValueError:x和y必须具有相同的第一维错误消息 .

我仍然是Python的新手,并试图创建一个简单的图形

这是我的代码:

将matplotlib.pyplot导入为plt

来自pylab import plot,show

月=范围(1,13)

nyc_temp_2000 = [20.0,30.5,80.1,80.3,56.5,99.6]

nyc_temp_2006 = [44.9,6.4,92.4,69.8,25.5,12.5]

nyc_temp_2012 = [60.5,60.9,66.2,25.0,10.0,78.0]

情节(月,nyc_temp_2000)

情节(月,nyc_temp_2006)

plot(months,nyc_temp_2012)show()

这是完整的痕迹:

Traceback(最近一次调用最后一次):

文件“”,第1行,在runfile中('D:/WinPython/WinPython-32bit-2.7.10.3/python-2.7.10/Scripts/Test_Scripts/NYC_Temps_2.py',wdir ='D:/ WinPython / WinPython-32bit -2.7.10.3 /蟒-2.7.10 /脚本/ Test_Scripts')

文件“D:\ WinPython \ WinPython-32bit-2.7.10.3 \ python-2.7.10 \ lib \ site-packages \ spyderlib \ widgets \ externalshell \ sitecustomize.py”,第790行,在runfile execfile(filename,namespace)中

在execfile exec中文件“D:\ WinPython \ WinPython-32bit-2.7.10.3 \ python-2.7.10 \ lib \ site-packages \ spyderlib \ widgets \ externalshell \ sitecustomize.py”,第77行(compile(scripttext,filename) ,'exec'),glob,loc)

文件“D:/WinPython/WinPython-32bit-2.7.10.3/python-2.7.10/Scripts/Test_Scripts/NYC_Temps_2.py”,第25行,在图中(月,nyc_temp_2000)

文件“D:\ WinPython \ WinPython-32bit-2.7.10.3 \ python-2.7.10 \ lib \ site-packages \ matplotlib \ pyplot.py”,第3154行,in plot ret = ax.plot(* args,** kwargs)

文件“D:\ WinPython \ WinPython-32bit-2.7.10.3 \ python-2.7.10 \ lib \ site-packages \ matplotlib__init __ . py”,第1815行,内部返回函数(ax,* args,** kwargs)

文件“D:\ WinPython \ WinPython-32bit-2.7.10.3 \ python-2.7.10 \ lib \ site-packages \ matplotlib \ axes_axes.py”,第1427行,在self._get_lines中的行的图中(* args,* * kwargs):

文件“D:\ WinPython \ WinPython-32bit-2.7.10.3 \ python-2.7.10 \ lib \ site-packages \ matplotlib \ axes_base.py”,第386行,在_grab_next_args中为seg in self._plot_args(其余,kwargs) :

文件“D:\ WinPython \ WinPython-32bit-2.7.10.3 \ python-2.7.10 \ lib \ site-packages \ matplotlib \ axes_base.py”,第364行,在_plot_args x中,y = self._xy_from_xy(x,y )

文件“D:\ WinPython \ WinPython-32bit-2.7.10.3 \ python-2.7.10 \ lib \ site-packages \ matplotlib \ axes_base.py”,第223行,在_xy_from_xy中引发ValueError(“x和y必须首先相同尺寸”)

ValueError:x和y必须具有相同的第一个维度

1 回答

  • 2

    你正在绘制6个温度点与12个月积分 . 您必须再添加6个温度值 .

相关问题