1. 单类别图
plt.figure(figsize = (15,8))
sns.boxplot(x="your_column1", y="your_column2", data=data_plot)
plt.xticks(rotation=90)
plt.show()
2. 多类别图
plt.figure(figsize = (20,15))
current_palette = sns.color_palette("Set2") #设置颜色
plt.title("图标题",fontsize=20) #设置标题
plt.xticks(rotation=60,fontsize=15) #设置横坐标字体大小、旋转角度
plt.yticks(fontsize=15) #设置纵坐标字体大小
plt.legend(loc = "best") #设置图例位置
#绘制箱体图,增加类别hue
fig = sns.boxplot(x="your_column1", y="your_column2",hue='your_column3', data=data_plot, palette=current_palette)
# plt.grid() #显示网格线
plt.show()
3. 延伸美化设置1:辅助线
#辅助线1
plt.hlines(30,-10,30,color="gray",linewidth = 1,linestyles='dashed')
plt.text(0, 30, '线上的标注1', ha ='left', va ='center')
#辅助线2
plt.hlines(60,-10,30,color="orange",linewidth = 1,linestyles='dashed')
plt.text(0, 60, '线上的标注2', ha ='left', va ='center')
#辅助线3
plt.hlines(100,-10,30,color="red",linewidth = 1,linestyles='dashed')
plt.text(0, 100, '线上的标注3', ha ='left', va ='center')
4. 延伸美化设置2:图片快照保存
#图片快照保存
snap_fig = fig.get_figure()
snap_fig.savefig(r'./path/filename.png', dpi = 400)
5. 相关包
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#mac设置中文字体显示
from matplotlib.font_manager import FontManager
fm = FontManager()
mat_fonts = set(f.name for f in fm.ttflist)
# print (mat_fonts)
plt.rcParams['font.sans-serif'] = ['Arial Unicode MS']