python画箱线图
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python画箱线图相关的知识,希望对你有一定的参考价值。
# -*- coding: utf-8 -*- """ Created on Wed Jun 14 13:00:11 2017 @author: Miao """ import numpy as np import scipy import matplotlib as mpl mpl.use(‘agg‘) import matplotlib.pyplot as plt from matplotlib.backends.backend_pdf import PdfPages from matplotlib import rc font = { ‘weight‘ : ‘normal‘} fig = plt.figure(1, figsize=(16, 8)) pp = PdfPages(‘test_100.pdf‘) T=[‘(a)‘,‘(b)‘,‘(c)‘,‘(d)‘,‘(e)‘,‘(f)‘]; data_name = [‘ORL‘,‘lung‘,‘JAFFE‘,‘COIL20‘,‘TOX_171‘,‘warpAR10P‘]; K = [‘5‘,‘20‘,‘100‘] i = 1 for j in range(len(data_name)): data = data_name[j] #for data in data_name: data1 = data+‘_100‘+‘.mat‘ mat1 = scipy.io.loadmat(data1) XX = mat1[‘Acc‘] XX = XX*100 ax = fig.add_subplot(2,3,i) bp = ax.boxplot(XX.T, patch_artist=True) if data is ‘TOX_171‘: data = ‘TOX\\_171‘ plt.title(T[j]+‘ ‘+data,fontsize=16) for box in bp[‘boxes‘]: box.set( color=‘#7570b3‘, linewidth=1) box.set( facecolor = ‘#1b9e77‘ ) for whisker in bp[‘whiskers‘]: whisker.set(color=‘#7570b3‘, linewidth=1) for cap in bp[‘caps‘]: cap.set(color=‘#7570b3‘, linewidth=2) for median in bp[‘medians‘]: median.set(color=‘#b2df8a‘, linewidth=1) for flier in bp[‘fliers‘]: flier.set(marker=‘o‘, color=‘#e7298a‘, alpha=0.5) # ax.set_xticklabels([‘F\\_score‘, ‘Trace\\_ratio‘,‘ReliefF‘, ‘Fisher\\_score‘,‘RFS‘,r‘$\\ell_{2,1-2}$‘],fontdict=font) i=i+1 # plt.xlabel(‘Data sets‘,fontsize=14) plt.ylabel(‘Accuracy (\\%)‘,fontsize=16) # plt.ylim(ytc[j]) plt.xticks(fontsize=16) plt.yticks(fontsize=16) plt.savefig(pp,format=‘pdf‘) pp.savefig() pp.close()
以上是关于python画箱线图的主要内容,如果未能解决你的问题,请参考以下文章
用ggplot2画箱线图叠加图层后变成一个很奇怪的样子,求救求救?