简体   繁体   中英

Plotly: How to save only main figure to png?

This code:

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")

Produces this:

在此处输入图像描述

I would like only the main contour plot saved, with no x and y labels and no colorbar.

I expect that I could take a reliable sub-area of the image, but maybe there's an easier way?

You can use:

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

Plot

在此处输入图像描述

Complete code:

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM