My goal was to maintain uniformity when designing some Plotly graphs for a small Python project.
After I defined a layout, I tried using it as an object or variable, but I couldn't figure out how to do it.
import plotly.express as px
df = px.data.gapminder().query("country=='Canada'")
fig = px.line(df, x="year", y="lifeExp", title='Life expectancy in Canada')
fig.show()
# basic graphic manipulation
fig.update_layout(xaxis_range=[1970, 2000])
fig.update_layout(font_size=20)
fig.show()
I couldn't figure out how to do the same manipulation on a different figure without duplicate code. In the Plotly line chart documentation, I am unable to find the relevant parameters,
What I expected was:
desired_layout = dict(font_size = 20, xaxis_range=[1970, 2000])
fig = px.line(df, x="year", y="lifeExp", title='Life expectancy in Canada', layout = desired_layout)
#or:
fig = px.line(df, x="year", y="lifeExp", title='Life expectancy in Canada', **desired_layout)
However, none of them work for me.
Are there any other options?

