无法得到我绘制2个列表的简单意图。 1dim-lists的长度都是相同的,list-values是简单的浮点数,只有逗号后面的数字。长变量名称可能是可疑的,因为我研究了一些pyplot不喜欢某些名称的情况。无论如何,代码看起来像这样(列表本身被打印+由我复制):
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)\Python\lib\site-packages\matplotlib\pyplot.py", line 2817, in plot
ret = ax.plot(*args, **kwargs)
File "C:\Program Files (x86)\Python\lib\site-packages\matplotlib\axes.py", line 3996, in plot
for line in self._get_lines(*args, **kwargs):
File "C:\Program Files (x86)\Python\lib\site-packages\matplotlib\axes.py", line 330, in _grab_next_args
for seg in self._plot_args(remaining, kwargs):
File "C:\Program Files (x86)\Python\lib\site-packages\matplotlib\axes.py", line 308, in _plot_args
x, y = self._xy_from_xy(x, y)
File "C:\Program Files (x86)\Python\lib\site-packages\matplotlib\axes.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
令人困惑的是,当打印这些列表并将其复制到一个新的空文件中时(使用新变量'l'和'k',pyplot可以工作。我试图绘制重复项(copy.copy()命令)列出并分配新的varNames,但遗憾的是没有成功。 因此,任何想法都受到高度赞赏。
答案 0 :(得分:1)
您正在伪造格式化字符串错误,它应该是:
plt.plot(countErrXPercent_allX_ABC, '.b', label='aErr < bErr')
如你所知,它正试图在你的清单上标出'.'
。
将pyplot
导入为plt
而不是P
也是常规。
import matplotlib.pyplot as plt
这样做可以让您的代码更容易让其他人阅读,并且可以让您更轻松地重复使用示例代码。