#Python_matplotlib简介
import matplotlib.pyplot as plt
from numpy import random
fig=plt.figure()
ax1=fig.add_subplot(2,2,1)
ax2=fig.add_subplot(2,2,2)
ax3=fig.add_subplot(2,2,3)
ax4=fig.add_subplot(2,2,4)
plt.plot(random.randn(50).cumsum(),'r--')
fig,axes=plt.subplots(2,2)
plt.subplots_adjust(wspace=None,hspace=None)
axes[0,0].hist(random.randn(500),bins=50,color='k',alpha=0.6)
axes[0,1].hist(random.randn(500),bins=50,color='r',alpha=0.5)
axes[1,0].hist(random.randn(500),bins=10,color='b',alpha=0.5)
axes[1,1].hist(random.randn(500),bins=20,color='b',alpha=1.0)
#alpha代表透明度
plt.plot(random.randn(50).cumsum(),'k^--')
#'k^--'用来设置先行和标记点
plt.show()
plt.plot(random.randn(50).cumsum(),'k^--',label='knight')
plt.legend(loc='best')
#利用label属性可以设置标签
plt.show()
print('1________\n',a1)
a1.plot()
plt.show()
#Series和DataFrame都是一个用于生成各类图表的Plot方法
a2.plot()
plt.show()
#DataFrame的plot方法会在subplot中为各列绘制以条线,并自动创建图例
a2.plot(style='--',alpha=0.4,xticks=np.arange(100,200,10),grid=True)
#style 设置风格
#alpha设置显示透明度
#kind可以是‘line’ 'bar' 'barh' 'kde'
#logy在Y轴上使用对数标签
#use_index将对象的索引用作刻度标签
#rot旋转刻度标签
#xticks用作x轴的刻度值
#yticks用作y轴的刻度值
#xlimX轴的界限
#ylimY轴的界限
#grid显示轴网格线
plt.show()
a2.plot(style='--',alpha=0.4,xticks=np.arange(100,200,10),grid=True,subplots=True,figsize=(1024,768),title='Matplotlib')
#sharex 共用X轴
#sharey 共用y轴
#figsize 用来设置图像大小
#title 用来设置图像标题
plt.show()
领取专属 10元无门槛券
私享最新 技术干货