下边代码会画出一个y=cos(x)
的图像:
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-2,2,100)
y=np.cos(np.pi*x)
plt.plot(x,y,'go')
plt.title(r"$y=\cos(\pi | time x$")
plt.show()
在Jupyter lab运行的时候,发现报错如下:
ModuleNotFoundError: No module named 'matplotlib'
conda install matplotlib -c https://mirrors.bfsu.edu.cn/anaconda/pkgs/main/ -n jupyterlabuse
从清华python源里边安装matplotlib
。
完成之后显示:
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
Note: you may need to restart the kernel to use updated packages.
运行结果如下图: