情节:如何只将主要人物保存到 png?

Plotly: How to save only main figure to png?

此代码:

fig = go.Figure(data =
go.Contour(
    z=[[10, 10.625, 12.5, 15.625, 20],
       [5.625, 6.25, 8.125, 11.25, 15.625],
       [2.5, 3.125, 5., 8.125, 12.5],
       [0.625, 1.25, 3.125, 6.25, 10.625],
       [0, 0.625, 2.5, 5.625, 10]]
))

fig.write_image("logs/test.png")

产生这个:

我只想保存主等高线图,没有 x 和 y 标签,也没有颜色条。

我希望我可以拍摄图像的可靠子区域,但也许有更简单的方法?

您可以使用:

fig.update_traces(showscale=False)
fig.update_layout(yaxis={'visible': False, 'showticklabels': False},
                  xaxis={'visible': False, 'showticklabels': False})

情节

完整代码:

import plotly.graph_objects as   go

fig = go.Figure(data =
go.Contour(
    z=[[10, 10.625, 12.5, 15.625, 20],
       [5.625, 6.25, 8.125, 11.25, 15.625],
       [2.5, 3.125, 5., 8.125, 12.5],
       [0.625, 1.25, 3.125, 6.25, 10.625],
       [0, 0.625, 2.5, 5.625, 10]]
))

fig.update_traces(showscale=False)
fig.update_layout(yaxis={'visible': False, 'showticklabels': False},
                  xaxis={'visible': False, 'showticklabels': False})
fig.show()

fig.write_image("contour2.png")