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

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

问题描述

plotly.express 非常方便生成漂亮的交互式绘图.下面的代码生成按国家/地区着色的折线图.现在我需要在情节中添加点.有谁知道我如何向折线图添加点?

将 plotly.express 导入为 pxgapminder = px.data.gapminder().query("大陆=='大洋洲'")fig = px.line(gapminder, x="year", y="lifeExp", color='country')图.show()

解决方案

更新:

截至版本

代码:

将 plotly.express 导入为 pxgapminder = px.data.gapminder().query("continent=='Oceania'")fig = px.line(gapminder, x="year", y="lifeExp", color='country')fig.update_traces(mode='markers+lines')图.show()

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

解决方案

Update:

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

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

Previousanswerforolderversions:

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

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)