今天学习了一下python的画图方法,感觉还不错,我用subplot画了几个不同类型的简单图
import numpy as np
import matplotlib.pyplot as plt
plt.subplot(2,1,1)
x=np.linspace(1,10,10)
y=x+5
plt.bar(x,y,facecolor='green',edgecolor='blue')
plt.ylim(0,+20)
for xx,yy in zip(x,y):
plt.text(xx,yy+1,str(yy),ha='center')
plt.subplot(2,2,3)
z=np.random.rand(5)
plt.pie(z,shadow=True,autopct='%.1f %%')
plt.subplot(2,2,4)
x=np.linspace(0,10,10000)
y=np.sin(x)
z=np.cos(x**2)
q=x/10
plt.plot(x,y,label="$sin(x)$",color="red",linewidth=2)
plt.plot(x,z,label="$cos(x^2)$",color="green",linewidth=2)
plt.plot(x,q,label="$x/10$",color="blue",linewidth=2)
plt.xlabel("Time(s)")
plt.ylabel("Volt")
plt.title("First Example")
plt.ylim(-1.2,1.2)
plt.legend()
plt.show()
最终的结果如下所示: