python绘图
绘制函数图像
绘制函数 \(y=sin(x)\) 的图像
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 2*np.pi, 0.01)
y = np.sin(x)
plt.figure(1)
plt.plot(x, y)
plt.show()
![](https://img2020.cnblogs.com/blog/271257/202008/271257-20200829125347262-526577331.png)
绘制方程图像
绘制方程 \(x^2+2xy^2+3y^2=1\) 的图像
import numpy as np
import matplotlib.pyplot as plt
x=np.arange(-2,2,0.01)
y=np.arange(-2,2,0.01)
# 转化为网格
x,y=np.meshgrid(x,y)
z=np.power(x,2)+2*x*y+3*np.power(y,2)-1
# 绘制等高线
plt.contour(x,y,z,0)
plt.show()
![](https://img2020.cnblogs.com/blog/271257/202008/271257-20200829131301055-1653795190.png)