I'm running Python 2.7 and I keep getting this
我运行的是Python 2.7,我一直得到这个。
ValueError: x and y must have same first dimension error message.
ValueError: x和y必须具有相同的第一维错误消息。
I'm still pretty new to Python and trying to create a simple graph
我对Python还是相当陌生的,并且尝试创建一个简单的图
Here is my code:
这是我的代码:
import matplotlib.pyplot as plt
from pylab import plot, show
从pylab导入图,显示。
months = range(1, 13)
个月=范围(13)
nyc_temp_2000 = [20.0, 30.5, 80.1, 80.3, 56.5, 99.6]
nyc_temp_2000 =(20.0,30.5,80.1,20.0,30.5,99.6)
nyc_temp_2006 = [44.9, 6.4, 92.4, 69.8, 25.5, 12.5]
nyc_temp_2006 =(44.9,6.4,92.4,44.9,6.4,12.5)
nyc_temp_2012 = [60.5, 60.9, 66.2, 25.0, 10.0, 78.0]
nyc_temp_2012 =(60.5,60.9,66.2,60.5,60.9,78.0)
plot(months, nyc_temp_2000)
情节(月,nyc_temp_2000)
plot(months, nyc_temp_2006)
情节(月,nyc_temp_2006)
plot(months, nyc_temp_2012) show()
情节(月,nyc_temp_2012)()
Here is the full trace:
以下是完整的痕迹:
Traceback (most recent call last):
回溯(最近一次通话):
File "", line 1, in 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/python-2.7.10/Scripts/Test_Scripts')
文件“”,第1行,在runfile('D:/WinPython/WinPython-32bit-2.7.10.3/python-2.7.10/Scripts/ NYC_Temps_2)中。py’,wdir = ' D:/ WinPython WinPython-32bit-2.7.10.3 / python-2.7.10 /脚本/ Test_Scripts”)
File "D:\WinPython\WinPython-32bit-2.7.10.3\python-2.7.10\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 790, in runfile execfile(filename, namespace)
文件“D:\ WinPython \ WinPython-32bit-2.7.10.3 \ python-2.7.10 \ lib \ \ externalshell \ sitecustomize网站\ spyderlib \小部件。在runfile execfile(文件名,名称空间)中,第790行
File "D:\WinPython\WinPython-32bit-2.7.10.3\python-2.7.10\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 77, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc)
文件“D:\ WinPython \ WinPython-32bit-2.7.10.3 \ python-2.7.10 \ lib \ \ externalshell \ sitecustomize网站\ spyderlib \小部件。在execfile exec中,第77行(compile(scripttext, filename, 'exec'), glob, loc)
File "D:/WinPython/WinPython-32bit-2.7.10.3/python-2.7.10/Scripts/Test_Scripts/NYC_Temps_2.py", line 25, in plot(months, nyc_temp_2000)
文件“D:/ WinPython / / Test_Scripts / NYC_Temps_2 WinPython-32bit-2.7.10.3 / python-2.7.10 /脚本。py",第25行,在plot(months, nyc_temp_2000)
File "D:\WinPython\WinPython-32bit-2.7.10.3\python-2.7.10\lib\site-packages\matplotlib\pyplot.py", line 3154, in plot ret = ax.plot(*args, **kwargs)
文件“D:\ WinPython \ WinPython-32bit-2.7.10.3 \ python-2.7.10 \ lib \网站\ matplotlib \ pyplot。在图ret = ax中,第3154行。情节(* args,* * kwargs)
File "D:\WinPython\WinPython-32bit-2.7.10.3\python-2.7.10\lib\site-packages\matplotlib__init__.py", line 1815, in inner return func(ax, *args, **kwargs)
文件“D:\ WinPython \ WinPython-32bit-2.7.10.3 \ python-2.7.10 \ lib \网站\ matplotlib__init__。py",第1815行,in inner return func(ax, *args, *kwargs)
File "D:\WinPython\WinPython-32bit-2.7.10.3\python-2.7.10\lib\site-packages\matplotlib\axes_axes.py", line 1427, in plot for line in self._get_lines(*args, **kwargs):
文件“D:\ WinPython \ WinPython-32bit-2.7.10.3 \ python-2.7.10 \ lib \网站\ matplotlib \ axes_axes。第1427行,在《自我》的情节中。* * kwargs _get_lines(* args):
File "D:\WinPython\WinPython-32bit-2.7.10.3\python-2.7.10\lib\site-packages\matplotlib\axes_base.py", line 386, in _grab_next_args for seg in self._plot_args(remaining, kwargs):
文件“D:\ WinPython \ WinPython-32bit-2.7.10.3 \ python-2.7.10 \ lib \网站\ matplotlib \ axes_base。py",第386行,在_grab_next_args中用于seg in self。kwargs _plot_args(剩余的):
File "D:\WinPython\WinPython-32bit-2.7.10.3\python-2.7.10\lib\site-packages\matplotlib\axes_base.py", line 364, in _plot_args x, y = self._xy_from_xy(x, y)
文件“D:\ WinPython \ WinPython-32bit-2.7.10.3 \ python-2.7.10 \ lib \网站\ matplotlib \ axes_base。在_plot_args x中,y = self。_xy_from_xy(x,y)
File "D:\WinPython\WinPython-32bit-2.7.10.3\python-2.7.10\lib\site-packages\matplotlib\axes_base.py", line 223, in _xy_from_xy raise ValueError("x and y must have same first dimension")
文件“D:\ WinPython \ WinPython-32bit-2.7.10.3 \ python-2.7.10 \ lib \网站\ matplotlib \ axes_base。py,第223行,在_xy_from_xy中增加ValueError(“x和y必须具有相同的第一个维度”)
ValueError: x and y must have same first dimension
ValueError: x和y必须具有相同的第一个维度
1 个解决方案
#1
2
you are plotting 6 temperature points versus 12 month points. You have to add 6 more temperature values.
你绘制了6个温度点和12个月点。你需要增加6个温度值。
#1
2
you are plotting 6 temperature points versus 12 month points. You have to add 6 more temperature values.
你绘制了6个温度点和12个月点。你需要增加6个温度值。