【问题标题】:How to get rid of gridlines in all the subplots of scatter_matrix in plotly?如何在情节中摆脱 scatter_matrix 的所有子图中的网格线?
【发布时间】:2021-12-28 12:47:30
【问题描述】:

我正在尝试摆脱 scatter_matrix 图的所有子图中的网格线。我已将 x 轴和 y 轴的 showgrid 参数设置为 False,但大多数子图确实仍然显示网格线。我该如何解决这个问题?

这是我的代码:

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))
fig.for_each_yaxis(lambda x: x.update(showgrid=False))
fig.show()

这是图片:

【问题讨论】:

    标签: plotly gridlines scatter-matrix


    【解决方案1】:
    • 轴不在布局中,因此您使用的方法不起作用。 update_xaxes()update_yaxes() 也不起作用
    • 使用 dict 理解来明确设置 10 个 x&y 轴确实有效
    fig.update_layout(
        {
            f"{ax}axis{n+1 if n>0 else ''}": {"showgrid": False}
            for n, ax in itertools.product(range(10), list("xy"))
        }
    )
    
    

    【讨论】:

      猜你喜欢
      • 2021-12-02
      • 2021-01-17
      • 1970-01-01
      • 2015-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-06
      相关资源
      最近更新 更多