weixin_43328079
本地磁盘A
采纳率66.7%
2019-02-20 21:27

用matplotlib画个图这简单的四行代码都能出错?

已采纳

以下是代码:

import matplotlib.pyplot as plt

plt.plot(range(1,6),[1,2,3,4,5],'bo',lable='Training')
plt.plot(range(1,6),[1,0,0,0,2],'bo',lable='Test')
plt.legend()
plt.show()

以下是错误提示:
Traceback (most recent call last):
  File "test.py", line 3, in <module>
    plt.plot(range(1,6),[1,2,3,4,5],'bo',lable='Training')
  File "D:\Anaconda\lib\site-packages\matplotlib\pyplot.py", line 3161, in plot
    ret = ax.plot(*args, **kwargs)
  File "D:\Anaconda\lib\site-packages\matplotlib\__init__.py", line 1818, in inner
    return func(ax, *args, **kwargs)
  File "D:\Anaconda\lib\site-packages\matplotlib\axes\_axes.py", line 1382, in plot
    for line in self._get_lines(*args, **kwargs):
  File "D:\Anaconda\lib\site-packages\matplotlib\axes\_base.py", line 381, in _grab_next_args
    for seg in self._plot_args(remaining, kwargs):
  File "D:\Anaconda\lib\site-packages\matplotlib\axes\_base.py", line 369, in _plot_args
    seg = func(x[:, j % ncx], y[:, j % ncy], kw, kwargs)
  File "D:\Anaconda\lib\site-packages\matplotlib\axes\_base.py", line 276, in _makeline
    seg = mlines.Line2D(x, y, **kw)
  File "D:\Anaconda\lib\site-packages\matplotlib\lines.py", line 380, in __init__
    self.update(kwargs)
  File "D:\Anaconda\lib\site-packages\matplotlib\artist.py", line 859, in update
    raise AttributeError('Unknown property %s' % k)
AttributeError: Unknown property lable

最后两行是什么意思??
画的图也没有显示label。

我试了一下删掉plot后面的label参数,即

import matplotlib.pyplot as plt

plt.plot(range(1,6),[1,2,3,4,5],'bo')
plt.plot(range(1,6),[1,0,0,0,2],'bo')
plt.legend()
plt.show()

虽然能把图画出来,但是会有以下警告:
D:\Anaconda\lib\site-packages\matplotlib\axes\_axes.py:531: UserWarning: No labelled objects found. Use label='...' kwarg on individual plots.
  warnings.warn("No labelled objects found. "

意思是我需要添加一个label=‘...’
但是添加之后又会有上面那个错误,这到底该咋整啊。。。。。。?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • caozhy 回答这么多问题就耍赖把我的积分一笔勾销了 2年前

    label 吧,你拼错了,成了lable

    点赞 2 评论 复制链接分享
  • zaq15csdn greatofdream 2年前

    raise抛出异常
    label写错了,没有属性lable

    点赞 1 评论 复制链接分享