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.
More than a year later I ended up with the same issue, and Google brought me here. Posting here the solution for quick reference:
fig.update_traces(opacity=.4)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With