boxplot——matplotlib箱型图画法
%matplotlib inline
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
plt.figure(figsize=(15,7))
#第⼀个图表
plt.subplot(121)
plt.title('(a)1',fontsize=12)#标题,并设定字号⼤⼩
df = pd.DataFrame(np.random.rand(50,2),columns=['A','B'])
#data.boxplot(vert=False,grid=False,patch_artist=True,meanline=True,showmeans=True,showfliers=False,sym='.',figsize= (12,8),fontsize=15,boxprops = {'color':'orangered','facecolor':'pink'})
ax=df.boxplot(vert=True,showfliers=False,grid=False,figsize=(8,8),widths=0.8)
matplotlib中subplotax.set_xlabel("Type Transition",fontdict={'family' : 'Times New Roman', 'size'  : 14})
ax.set_ylabel("Percentage(%)",fontdict={'family' : 'Times New Roman', 'size'  : 14})
#a()
#ax为两条坐标轴的实例
#ax.xaxis.set_major_locator(x_major_locator)
#把x轴的主刻度设置为1的倍数
#ax.set_xticklabels(labels=["CN - CN","CN - LK"],rotation=300)
plt.subplot(122)
plt.title('(b) 2',fontsize=12)#标题,并设定字号⼤⼩
df = pd.DataFrame(np.random.rand(50,2),columns=['C','D'])
#data.boxplot(vert=False,grid=False,patch_artist=True,meanline=True,showmeans=True,showfliers=False,sym='.',figsize= (12,8),fontsize=15,boxprops = {'color':'orangered','facecolor':'pink'})
ax=df.boxplot(vert=True,showfliers=False,grid=False,figsize=(8,8),widths=0.8)
ax.set_xlabel("Type Transition",fontdict={'family' : 'Times New Roman', 'size'  : 14})
ax.set_ylabel("Percentage(%)",fontdict={'family' : 'Times New Roman', 'size'  : 14})
#ax.set_xticklabels(labels=["CN - CN","CN - LK"],rotation=300)
plt.savefig('boxplot.jpg',dpi=1000, bbox_inches='tight') plt.show()#显⽰图像

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。