I want to make the size of the graph automatic with plotly.

Asked 2 years ago, Updated 2 years ago, 152 views

What should I do if I want to make a graph by specifying the size of the graph once and then automatically mold the size of the graph?
The purpose is to create a graph that automatically changes size and size, save it in html, and print it if you specify the size.If the size changes automatically, I want to use it to display the right size according to the resolution of the monitor I use.

#imports
import pandas aspd
import plotly.graph_objs as go
import numpy as np

# data
np.random.seed(4)
x = np.linspace(0,1,50)
y=np.cumsum(np.random.randn(50))

# plotly line chart
config=go.Figure(data=go.Scatter(x=x,y=y,mode='lines'),layout_yaxis_range=[-4,4])
config.update_layout(
    width = 1000,
    height = 1000*2**0.5,
)              
config.show()
config.update_layout(
    autosize = True
) 
config.show()

If you want to generate html,

#imports
import pandas aspd
import plotly.graph_objs as go
import numpy as np

# data
np.random.seed(4)
x = np.linspace(0,1,50)
y=np.cumsum(np.random.randn(50))

# plotly line chart
config=go.Figure(data=go.Scatter(x=x,y=y,mode='lines'),layout_yaxis_range=[-4,4])
config.update_layout(
    width = 1000,
    height = 1000*2**0.5,
)              
config.write_html("a.html")
config.update_layout(
    autosize = True
) 
config.write_html("aa.html")

I want to see graphs of different sizes (one side wants to change size automatically)

python plotly-python

2022-09-29 21:59

1 Answers

You may have come to understand what the problem is, rather than a hint.
Even if you specify autosize=True in the second, the width=1000, height=1000*2**0.5, you specified before that remains, so it may be affected.
Why don't you look for the ability to erase or relativize the first fixed size specification? If you don't have it, do you want to remake the second one from the beginning?

For the time being, I think we can do it if we remake the second one from the beginning as follows.

#plotly line chart
config=go.Figure(data=go.Scatter(x=x,y=y,mode='lines'),layout_yaxis_range=[-4,4])
config.update_layout(
    width = 1000,
    height = 1000*2**0.5,
)              
config.show()
#### And the second graph, again, we're going to start from the beginning.
config=go.Figure(data=go.Scatter(x=x,y=y,mode='lines'),layout_yaxis_range=[-4,4])###
config.update_layout(
    autosize = True
) 
config.show()

@metropolis, I think the comment method is valid with the same results.

 config.update_layout(
    width = None,
    height = None,
    autosize = True
)


2022-09-29 21:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.