8

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()
rzaratx
  • 756
  • 3
  • 9
  • 29
  • You can use the `scale` parameter to increase the resolution of the image, e.g. `fig.write_image("fig_name.png", scale=5)`, see the [Plotly documentation](https://plotly.github.io/plotly.py-docs/generated/plotly.io.write_image.html) for more details. – Flavia Giammarino Aug 20 '21 at 17:37
  • 1
    @FlaviaGiammarino That increased the size but it is saving the default view. Can it save from a different angle? – rzaratx Aug 20 '21 at 17:43

1 Answers1

9

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.

Hamzah
  • 8,175
  • 3
  • 19
  • 43