Plotly: How to combine scatter and line plots using Plotly Express?(Plotly:如何使用 Plotly Express 组合散点图和线图?)
问题描述
Plotly Express 有一种直观的方式,可以用最少的代码行提供预先格式化的绘图;有点像 Seaborn 是如何为 matplotlib 做的.
可以在 Plotly 上添加绘图轨迹,以在现有线图上获得散点图.但是,我在 Plotly Express 中找不到这样的功能.
是否可以在 Plotly Express 中结合散点图和折线图?
你可以使用:
fig3 = go.Figure(data=fig1.data + fig2.data)
fig1
和 fig2
是使用
Plotly Express has an intuitive way to provide pre-formatted plotly plots with minimal lines of code; sort of how Seaborn does it for matplotlib.
It is possible to add traces of plots on Plotly to get a scatter plot on an existing line plot. However, I couldn't find such a functionality in Plotly Express.
Is it possible to combine a scatter and line graph in Plotly Express?
You can use:
fig3 = go.Figure(data=fig1.data + fig2.data)
Where fig1
and fig2
are built using px.line()
and px.scatter()
, respectively. And fig3
is, as you can see, built using plotly.graph_objects
.
Some details:
One approach that I use alot is building two figures fig1
and fig2
using plotly.express
and then combine them using their data attributes together with a go.Figure / plotly.graph_objects
object like this:
import plotly.express as px
import plotly.graph_objects as go
df = px.data.iris()
fig1 = px.line(df, x="sepal_width", y="sepal_length")
fig1.update_traces(line=dict(color = 'rgba(50,50,50,0.2)'))
fig2 = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
fig3 = go.Figure(data=fig1.data + fig2.data)
fig3.show()
Plot:
这篇关于Plotly:如何使用 Plotly Express 组合散点图和线图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Plotly:如何使用 Plotly Express 组合散点图和线图?
基础教程推荐
- 用于分类数据的跳跃记号标签 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 筛选NumPy数组 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01