堆栈绘图表达线图ATOP graph_objects填充散点图

发布于 2025-02-01 03:13:51 字数 778 浏览 3 评论 0原文

我想堆叠plotly.express line绘图在graph_objects的填充矩形上。用px.line创建图形,然后添加填充的矩形使矩形显示在行上方(笔记本)。

import plotly.express as px
import plotly.graph_objects as go

fig = px.line(x=[0, 2, 4], y=[1, 2, 3])
fig.add_trace(go.Scatter(
    x=[1, 1, 3, 3, 1], 
    y=[0, 5, 5, 0, 0],
    fill="toself")
)
fig.show()

如何在矩形上方获得线路?

I'd like to stack a plotly.express line plot atop a filled rectangle from graph_objects. Creating the figure with px.line and then adding the filled rectangle makes the rectangle show up above the line (notebook).

import plotly.express as px
import plotly.graph_objects as go

fig = px.line(x=[0, 2, 4], y=[1, 2, 3])
fig.add_trace(go.Scatter(
    x=[1, 1, 3, 3, 1], 
    y=[0, 5, 5, 0, 0],
    fill="toself")
)
fig.show()

plot with

How can I get the line above the rectangle?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在深巷 2025-02-08 03:13:51

应用答案 to 在plotly.express中添加痕迹

fig = go.Figure()
fig.add_trace(go.Scatter(
    x=[1, 1, 3, 3, 1], 
    y=[0, 5, 5, 0, 0],
    fill="toself")
)
fig.add_traces(list(px.line(x=[0, 2, 4], y=[1, 2, 3]).select_traces()))
fig.show()

”在此处输入图像说明”

Applying the answer to How to add traces in plotly.express :

fig = go.Figure()
fig.add_trace(go.Scatter(
    x=[1, 1, 3, 3, 1], 
    y=[0, 5, 5, 0, 0],
    fill="toself")
)
fig.add_traces(list(px.line(x=[0, 2, 4], y=[1, 2, 3]).select_traces()))
fig.show()

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文