'Can I save a high resolution image of my plotly scatter plot?

Can I set a parameter for plotly.graph_objs.go.Scatter3d to either make the graph full screen or to set the save resolution higher? The current resolution that is being saved when using the built in save plot function is 983x525. I would like to at least get it to 1080p.

trans = .6
trace1 = go.Scatter3d(
                    x = cluster0["PC1_3d"],
                    y = cluster0["PC2_3d"],
                    z = cluster0["PC3_3d"],
                    mode = "markers",
                    name = "Cluster 0",
                    marker = dict(color = f'rgba(255, 0, 0, {trans})'),
                    text = None)

trace2 = go.Scatter3d(
                    x = cluster1["PC1_3d"],
                    y = cluster1["PC2_3d"],
                    z = cluster1["PC3_3d"],
                    mode = "markers",
                    name = "Cluster 1",
                    marker = dict(color = f'rgba(0, 0, 204, {trans})'),
                    text = None)

trace3 = go.Scatter3d(
                    x = cluster2["PC1_3d"],
                    y = cluster2["PC2_3d"],
                    z = cluster2["PC3_3d"],
                    mode = "markers",
                    name = "Cluster 2",
                    marker = dict(color = f'rgba(0, 204, 0, {trans})'),
                    text = None)

trace4 = go.Scatter3d(
                    x = cluster3["PC1_3d"],
                    y = cluster3["PC2_3d"],
                    z = cluster3["PC3_3d"],
                    mode = "markers",
                    name = "Cluster 3",
                    marker = dict(color = f'rgba(255, 0, 255, {trans})'),
                    text = None)

trace5 = go.Scatter3d(
                    x = cluster4["PC1_3d"],
                    y = cluster4["PC2_3d"],
                    z = cluster4["PC3_3d"],
                    mode = "markers",
                    name = "Cluster 4",
                    marker = dict(color = f'rgba(255, 128, 0, {trans})'),
                    text = None)

data = [trace1, trace2, trace3, trace4, trace5]

title = "TEST"

layout = dict(title = title,
              xaxis= dict(title= 'PC1',ticklen= 5,zeroline= False),
              yaxis= dict(title= 'PC2',ticklen= 5,zeroline= False))
    
fig1 = go.Figure(data = data, layout = layout)
fig1.show()


Solution 1:[1]

Option 1: You can use this:

import plotly.io as pio
pio.write_image(fig, 'image.pdf',scale=6, width=1080, height=1080)

You can read here, you will find that there are different formats, and also you can scale the image in pixels. I used .png format, and it is high resolution image.

Option 2:

config = {
  'toImageButtonOptions': {
    'format': 'png', # one of png, svg, jpeg, webp
    'filename': 'custom_image',
    'height': 500,
    'width': 700,
    'scale':6 # Multiply title/legend/axis/canvas sizes by this factor
  }
}


fig.show(config=config)

Click the download icon from the upper left of the figure and open the saved image and zoom it in, you will find it high-resolution image. You can also change the height, width, and scale(resolution) together.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1