How to add points to line chart using plotly express?

痞子三分冷 提交于 2020-11-29 04:47:07

问题


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

回答1:


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

Plot:

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


来源:https://stackoverflow.com/questions/58637369/how-to-add-points-to-line-chart-using-plotly-express

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!