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)

ax.set_xlabel("Type Transition",fontdict={'family' : 'Times New Roman', 'size'  : 14})

ax.set_ylabel("Percentage(%)",fontdict={'family' : 'Times New Roman', 'size'  : 14})

#ax=plt.gca()

#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()#显示图像


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容