1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python-matplotlib-箱线图为不同的箱体设置不同颜色

python-matplotlib-箱线图为不同的箱体设置不同颜色

时间:2018-08-06 18:37:04

相关推荐

python-matplotlib-箱线图为不同的箱体设置不同颜色

箱线图怎么为不同的箱体设置不同颜色?

方法:

f=df.boxplot(patch_artist=True,return_type='dict')# 这里共有四个boxcolor=['k', 'g', 'r', 'deepskyblue'] # 有多少box就对应设置多少颜色for box,c in zip(f['boxes'], color):# 箱体边框颜色box.set( color=c, linewidth=2)# 箱体内部填充颜色box.set( facecolor = c )

实战:

%matplotlib notebookfig, ax = plt.subplots(1, 6,figsize=(9.5, 2.5))color=['r','g']labels = ["epilepsy","no_epilepsy"]ax1 = plt.subplot(161)f1 = ax1.boxplot(np.array([preprocessing.scale(np.mean(psd_e[:,:,:], axis=1)),preprocessing.scale(np.mean(psd_en[:,:,:], axis=1))]),showfliers=False,patch_artist=True,labels = labels)plt.xticks([])plt.ylabel('z-score')plt.xlabel('A')for box,c in zip(f1['boxes'], color):# 箱体内部填充颜色box.set( facecolor = c )ax2 = plt.subplot(162)f2 = ax2.boxplot(np.array([preprocessing.scale(np.mean(pywt_energy_e[:,:,:], axis=1)),preprocessing.scale(np.mean(pywt_energy_en[:,:,:], axis=1))]),showfliers=False,patch_artist=True)plt.xticks([])plt.xlabel('B')for box,c in zip(f2['boxes'], color):# 箱体内部填充颜色box.set( facecolor = c )ax3 = plt.subplot(163)f3 = ax3.boxplot(np.array([preprocessing.scale(np.mean(pywt_energyRate_e[:,:,:], axis=1)),preprocessing.scale(np.mean(pywt_energyRate_en[:,:,:], axis=1))]),showfliers=False,patch_artist=True)plt.xticks([])plt.xlabel('C')for box,c in zip(f3['boxes'], color):# 箱体内部填充颜色box.set( facecolor = c )ax4 = plt.subplot(164)f4 = ax4.boxplot(np.array([preprocessing.scale(np.mean(pywt_entropy_e[:,:,:], axis=1)),preprocessing.scale(np.mean(pywt_entropy_en[:,:,:], axis=1))]),showfliers=False,patch_artist=True)plt.xticks([])plt.xlabel('D')for box,c in zip(f4['boxes'], color):# 箱体内部填充颜色box.set( facecolor = c )ax5 = plt.subplot(165)f5 = ax5.boxplot(np.array([preprocessing.scale(np.mean(peEntropy_e[:,:,0], axis=1)),preprocessing.scale(np.mean(peEntropy_en[:,:,0], axis=1))]),showfliers=False,patch_artist=True,labels = labels)plt.xticks([])plt.xlabel("E")for box,c in zip(f5['boxes'], color):# 箱体内部填充颜色box.set( facecolor = c )ax6 = plt.subplot(166)f6 = ax6.boxplot(np.array([preprocessing.scale(np.mean(shEntropy_e[:,:,0], axis=1)),preprocessing.scale(np.mean(shEntropy_en[:,:,0], axis=1))]),showfliers=False,patch_artist=True,labels = labels)plt.xticks([])plt.xlabel('F')for box,c in zip(f6['boxes'], color):# 箱体内部填充颜色box.set( facecolor = c )plt.tight_layout()plt.show()plt.savefig("./minist.jpg")

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。