You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Python的Plotly px.box中隐藏箱线图的异常值?

解决Plotly箱线图隐藏异常值的问题

你可以通过以下两种方式实现隐藏箱线图中的异常值:

方法一:直接在px.box()中设置参数

修改你的代码,添加points=False参数即可:

fig = px.box(df, x=x_column, y=y_column, color=x_column, points=False)    
st.plotly_chart(fig, use_container_width=True)

points参数默认值为'outliers',会自动显示箱线图的异常值点;设置为False后,所有散点(包括异常值)都会被隐藏。

方法二:通过update_traces()精细控制

如果需要保留其他配置,仅单独隐藏异常值,可以用轨迹更新的方式:

fig = px.box(df, x=x_column, y=y_column, color=x_column)
# 遍历所有图表轨迹,关闭异常值显示
fig.update_traces(boxpoints=False)
st.plotly_chart(fig, use_container_width=True)

这种方式直接修改箱线图的轨迹属性,同样能达到隐藏异常值的效果。

内容的提问来源于stack exchange,提问作者olive

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 11:20:37