Reputation: 1213
I'm unclear how to style a line in a plotly express figure, altering color and width. The plotly documentation offers suggestions to style lines using go, but I do not see information for px.
Example
import plotly.express as px
df = px.data.gapminder().query("continent=='Oceania'")
fig = px.line(df, x="year", y="lifeExp", color='country')
fig.show()
I tried putting line=dict(color='firebrick', width=4)
as an argument of px.line
but that throws the error line() got an unexpected keyword argument 'line'
as it is code for go rather than px.
Upvotes: 9
Views: 20643
Reputation: 1213
Plotly px line styles can be updated with update_traces
function see documentation for further information. The following example modifies the prior figure making all of the lines black and thin.
import plotly.express as px
df = px.data.gapminder().query("continent=='Oceania'")
fig = px.line(df, x="year", y="lifeExp", color='country')
# This styles the line
fig.update_traces(line=dict(color="Black", width=0.5))
fig.show()
Upvotes: 27