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

如何去除Plotly中scatter_matrix所有子图的网格线?

问题原因

Plotly 中 scatter_matrix 底层基于 splom 类型 trace 实现,网格线分为两类:

  • 坐标轴自带的网格线,由x/y轴的showgrid参数控制
  • splom trace 自带的子图分隔网格线,由trace自身的grid.showline参数控制,之前的操作只关闭了前者,所以还有残留网格线。

解决代码

import plotly.express as px
df = px.data.iris()
fig = px.scatter_matrix(df,
    dimensions=["sepal_width", "sepal_length", "petal_width", "petal_length"],
    color="species")
# 关闭所有坐标轴的网格线和零值线(零值线容易被误认为是残留网格)
fig.for_each_xaxis(lambda x: x.update(showgrid=False, zeroline=False))
fig.for_each_yaxis(lambda x: x.update(showgrid=False, zeroline=False))
# 关闭splom自带的子图分隔网格线
fig.update_traces(grid=dict(showline=False))
fig.show()

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 12:24:03