【798】Python中通过seaborn绘制violin plot
参考:python怎么绘制小提琴图?|seaborn violinplot
参考:01 ,seaborn 基本设置 :5种风格,外边框,图位置,子图风格,文字大小,线宽
参考:matplotlib科研绘图---Times New Roman字体设置
参考:学习 seaborn [08]: seaborn 绘图中设置字体及字体大小
☀☀☀<< 举例 >>☀☀☀
import seaborn as sns import matplotlib.pyplot as plt import pandas as pd; # 白色背景显示,可以设置多种形式 sns.set(style="white") # 设置横纵轴的显示以及字体大小 sns.set(style="ticks", font_scale=2) # 以下两句防止中文显示为窗格 # plt.rcParams["font.sans-serif"]=["SimHei"] # plt.rcParams["axes.unicode_minus"] = False # 修改显示字体 plt.rcParams['font.sans-serif'] = 'Times New Roman' # 导入数据,从excel中 # df = pd.read_excel('fu.xlsx') # 设置窗口的大小 f, ax = plt.subplots(figsize=(8, 5)) # 绘制小提琴图,颜色有多个库可供选择 sns.violinplot(data=df, palette=sns.color_palette("husl", 6)[4:6], bw=.2, cut=1, linewidth=2) # 设置横纵轴的标题内容 ax.set(ylabel='Mean distance', xlabel='Transportation mode') # 设置轴显示的范围 #ax.set(ylim=(-.7, 1.05)) # 去除上下左右的边框(默认该函数会取出右上的边框) # sns.despine(left=True, bottom=True) # 设置打印精度,“tight”可以紧密显示,完整显示,存储为PDF为食量图像 plt.savefig('violin_di_mean.pdf',dpi=200,bbox_inches="tight")
局部微调
参考:python画图显示在哪设置_python画图设置坐标轴的位置及角度及设置colorbar
df = pd.DataFrame(di_mean_arr_0[:len(ve_25p_arr_1)], columns=['Cycling']) df['Walking'] = di_mean_arr_1 sns.set(style="white") # adjust the font size sns.set(style="ticks", font_scale=3) plt.rcParams['font.sans-serif'] = 'Times New Roman' # adjust the figure size f, ax = plt.subplots(figsize=(8, 8)) ax = sns.violinplot(data=df, palette=sns.color_palette("husl", 6)[4:6], bw=.2, cut=1, linewidth=2) # adjust the orientation of the yticklabels ax.set_yticklabels(ax.get_yticklabels(), rotation=90) #ax.yaxis.set_minor_locator(MultipleLocator(0.1)) #ax.set(ylabel='Average distance', xlabel='Transportation mode') plt.savefig('violin_di_mean.pdf',dpi=200,bbox_inches="tight")
效果:
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
2021-01-14 【521】通过压缩文件安装 python library