matplotlib - python Pyplot错误:"ValueError: x and y must have same first dimension"


countErrXPercent_allX_ABC = [0, 0.0, 0.0, 4.55, 5.41, 15.69, 23.44, 29.27, 32.05, 47.95, 48.0, 64.91, 43.94, 57.35, 52.27, 70.59, 79.55, 73.53, 77.14, 64.52, 77.78, 80.0, 82.61, 72.0, 86.96, 74.07, 77.78, 66.67, 60.0, 55.56, 80.0, 90.91, 77.78, 75.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, -1.0, 100.0, 100.0]
countErrYPercent_allY_ABC = [0, -1.0, 0.0, 10.0, 12.5, 22.22, 43.59, 48.61, 53.42, 67.37, 71.83, 78.65, 74.32, 72.88, 68.97, 82.69, 88.37, 77.27, 84.62, 85.0, 86.67, 90.0, 93.94, 83.33, 87.5, 80.95, 83.33, 92.86, 83.33, 57.14, 81.82, 100.0, 75.0, 100.0, 100.0, 60.0, 100.0, 50.0, 83.33, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0]
P.plot(countErrXPercent_allX_ABC, '.', 'b', label='aErr < bErr')
P.plot(countErrYPercent_allY_ABC, '.', 'r', label='aErr < cErr')
P.show()

错误消息:


Traceback (most recent call last):
File"xyz.py", line 169, in errClassesX
P.plot(countErrXPercent_allX_ABC, '.', 'b', label='aErr < bErr')
File"C:Program Files (x86)Pythonlibsite-packagesmatplotlibpyplot.py", line 2817, in plot
ret = ax.plot(*args, **kwargs)
File"C:Program Files (x86)Pythonlibsite-packagesmatplotlibaxes.py", line 3996, in plot
for line in self._get_lines(*args, **kwargs):
File"C:Program Files (x86)Pythonlibsite-packagesmatplotlibaxes.py", line 330, in _grab_next_args
for seg in self._plot_args(remaining, kwargs):
File"C:Program Files (x86)Pythonlibsite-packagesmatplotlibaxes.py", line 308, in _plot_args
x, y = self._xy_from_xy(x, y)
File"C:Program Files (x86)Pythonlibsite-packagesmatplotlibaxes.py", line 248, in _xy_from_xy
raise ValueError("x and y must have same first dimension")
ValueError: x and y must have same first dimension

时间:

字符串格式错误,应该是:


plt.plot(countErrXPercent_allX_ABC, '.b', label='aErr < bErr')

pyplot导入为plt,而不是P


import matplotlib.pyplot as plt

这样做将使你的代码更容易被其他人阅读,并使重用示例代码更容易。

...