绘制sin和cos图像失败
这是我照书上写的代码
import numpy as np
import matplotlib.pyplot as plt # 绘制图像
x = np.arange(0, 6, 0.1)
y1 = np.sin(x)
y2 = np.cos(x)
plt.plot(x, y1, label="sin")
plt.plot(x, y2, linestyle = "--", lable="cos")
plt.xlabel("x")
plt.ylabel("y")
plt.title('sin & cos')
plt.legend()
plt.show()
这是书上的源代码
# coding: utf-8
import numpy as np
import matplotlib.pyplot as plt
# 生成数据
x = np.arange(0, 6, 0.1) # 以0.1为单位,生成0到6的数据
y1 = np.sin(x)
y2 = np.cos(x)
# 绘制图形
plt.plot(x, y1, label="sin")
plt.plot(x, y2, linestyle = "--", label="cos")
plt.xlabel("x") # x轴的标签
plt.ylabel("y") # y轴的标签
plt.title('sin & cos')
plt.legend()
plt.show()
这是错误提示
D:\Python311\python.exe D:\Python_project\Python书上代码\绘制图像.py
Traceback (most recent call last):
File "D:\Python_project\Python书上代码\绘制图像.py", line 9, in <module>
plt.plot(x, y2, linestyle = "--", lable="cos")
File "D:\Python311\Lib\site-packages\matplotlib\pyplot.py", line 2812, in plot
return gca().plot(
^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\matplotlib\axes\_axes.py", line 1688, in plot
lines = [*self._get_lines(*args, data=data, **kwargs)]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\matplotlib\axes\_base.py", line 311, in __call__
yield from self._plot_args(
^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\matplotlib\axes\_base.py", line 544, in _plot_args
return [l[0] for l in result]
^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\matplotlib\axes\_base.py", line 544, in <listcomp>
return [l[0] for l in result]
^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\matplotlib\axes\_base.py", line 537, in <genexpr>
result = (make_artist(x[:, j % ncx], y[:, j % ncy], kw,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\matplotlib\axes\_base.py", line 351, in _makeline
seg = mlines.Line2D(x, y, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\matplotlib\_api\deprecation.py", line 454, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\matplotlib\lines.py", line 393, in __init__
self._internal_update(kwargs)
File "D:\Python311\Lib\site-packages\matplotlib\artist.py", line 1223, in _internal_update
return self._update_props(
^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\matplotlib\artist.py", line 1197, in _update_props
raise AttributeError(
AttributeError: Line2D.set() got an unexpected keyword argument 'lable'
进程已结束,退出代码1
谢谢各位的指导