箱线图 / 小提琴图¶
用途:展示连续变量在分组间的分布特征,包括中位数、四分位数、异常值和分布形状。
交互式图表¶
小提琴图展示分布形态,内部箱线图显示中位数和四分位数,散点为各受试者数据。
生成代码¶
import plotly.express as px
# 箱线图+散点
fig = px.box(df, x="treatment", y="endpoint",
color="treatment",
points="all",
title="Distribution of Endpoint by Treatment Group")
fig.show()
# 小提琴图
fig = px.violin(df, x="treatment", y="endpoint",
color="treatment", box=True,
title="Violin Plot with Box Inside")
fig.show()