from plotnine import *
import pandas as pd
# 准备数据
df = pd.DataFrame({'hsCRP': [10, 20, 23, 4, 5, 10],
'group': ['ctrl', 'ctrl', 'ctrl', 'T2DM', 'T2DM', 'T2DM']})
# 绘制小提琴图
print(ggplot(df,aes(y='hsCRP',
x='group'))+
geom_violin()+
theme_minimal())
# 交换两组在x轴上的位置
print(ggplot(df,aes(y='hsCRP',
x='group'))+
geom_violin()+
scale_x_discrete(limits=['ctrl', 'T2DM'])+
theme_minimal())