如何使用plotly express向折线图添加点?

时间:2019-10-31 05:32:44

标签: python plotly plotly-python plotly-express

plotly.express非常便于生成漂亮的交互式图。下面的代码生成按国家/地区着色的折线图。现在,我需要在图上添加点。有人知道我如何在折线图中添加点吗?

import plotly.express as px

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

1 个答案:

答案 0 :(得分:1)

使用fig.update_traces(mode='markers+lines')

情节:

enter image description here

代码:

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()