alex_bn_lee

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

统计

【798】Python中通过seaborn绘制violin plot

参考:python怎么绘制小提琴图?|seaborn violinplot

参考:seaborn学习笔记(四):箱型图、小提琴图


参考:01 ,seaborn 基本设置 :5种风格,外边框,图位置,子图风格,文字大小,线宽

参考:matplotlib科研绘图---Times New Roman字体设置

参考:python 绘图若干经验总结

参考:学习 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")


局部微调

参考:matplotlib 修改坐标轴刻度值,刻度个数

参考: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")

效果:

 

posted on   McDelfino  阅读(619)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
历史上的今天:
2021-01-14 【521】通过压缩文件安装 python library
点击右上角即可分享
微信分享提示