如何使用plotly express向折线图添加点或标记? [英] How to add points or markers to line chart using plotly express?

查看:94
本文介绍了如何使用plotly express向折线图添加点或标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案

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

剧情:

代码:

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

这篇关于如何使用plotly express向折线图添加点或标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆