Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add points or markers to line chart using plotly express?

plotly.express is very convenient to produce nice interactive plots. The code below generates a line chart colored by country. Now what I need is to add points to the plot. Does anyone know how I can add points to the line chart?

import plotly.express as px

gapminder = px.data.gapminder().query("continent=='Oceania'")
fig = px.line(gapminder, x="year", y="lifeExp", color='country')
fig.show()
like image 398
zesla Avatar asked Oct 31 '19 05:10

zesla


1 Answers

Update:

As of version 5.2.1 you can use markers=True in:

px.line(df, x='year', y='lifeExp', color='country', markers=True)

Previous answer for older versions:

Use fig.update_traces(mode='markers+lines')

Plot:

enter image description here

Code:

import plotly.express as px

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

fig.update_traces(mode='markers+lines')
fig.show()
like image 62
vestland Avatar answered Sep 30 '22 13:09

vestland