matplotlib画数学图形,功能很丰富。
import matplotlib.pyplot as plt x=range(10) y=[k**2 for k in x] plt.plot(x,y,'go--',label='sample') plt.title('matplotlib',fonsize=20) plt.title('matplotlib',fontsize=20) plt.text(4,30,"point", fontsize=20) plt.xlabel("x轴",fontproperties="SimHei",fontsize=18) plt.ylabel("y轴",fontproperties="SimHei",fontsize=18) plt.legend(loc='lower right') plt.show() sample在右下位置用plt.legend(loc='upper left') 可以把sample设为左上位置。
多条线绘制
xx=np.array([k for k in x]) plt.plot(xx,xx,'b|-',xx,2*xx,'go--',xx,xx**2,'r<--') plt.show() 画多条线
import padas as pd >>> d=pd.DataFrame(np.arange(12).reshape(3,4)) >>> d 0 1 2 3 0 0 1 2 3 1 4 5 6 7 2 8 9 10 11 >>> >>> plt.plot(d) >>> plt.show()
多子图绘制
plt.subplot(1,2,1) d=pd.DataFrame( np.arange(12).reshape(3,4)) plt.plot(d) plt.subplot(1,2,2) s=pd.Series(list("Hello")) plt.plot(s) plt.show() 多子图绘制 import matplotlib.pyplot as plt import numpy as np t=np.arange(0.0,2.0,0.1) s=np.sin(t*np.pi) figure,ax=plt.subplots(2,2) ax[0][0].plot(t,s,'r*') ax[1][1].plot(t*2,s,'b--') plt.show() subplots多子图绘制画饼图
labels='A','B','C','D' fracs =[15,30.55, 44.44, 10] explode =[0, 0.1,0,0] #0.1 凸出部分 plt.axes(aspect=1) # 轴向比例 plt.pie(x=fracs,labels=labels, explode=explode, autopct='%3.1f %%', shadow=True, labeldistance=1.1 , startangle=90,pctdistance =0.6) plt.show() 画饼图matplotlib 还可以画柱状图,散点图;箱线图,直方图,雷达图等等。