Plotly line opacity with plotly.express

Viewed 1611

I am doing some line plots with plotly.express. As MWE we can consider any of the examples in the documentation, for example this one which is:

import plotly.express as px

df = px.data.gapminder().query("continent=='Oceania'")
fig = px.line(df, x="year", y="lifeExp", color='country', facet_row='country')
fig.show()

How would you change the opacity of the lines, without altering their color or any other of their properties?

I have tried to use fig.update_traces(line=dict(width=1, opacity=.4)), the width property works but opacity raises an error.

In the past with plotly.graph_objects I have used the answers to this question but this requires me to choose the color, this time I want plotly.express to do that for me. So I don't know the color of each trace.

0 Answers
Related