gpt4 book ai didi

python - 用 Python 中的多个 plot.ly 图形绘制图

转载 作者:行者123 更新时间:2023-12-04 13:48:01 26 4
gpt4 key购买 nike

我在 plot.ly 中制作了 4 个数字,例如:

import plotly.plotly as py
import plotly.graph_objs as go

trace1 = go.Scatter(
x=[0, 1, 2, 3, 4, 5, 6, 7, 8],
y=[8, 7, 6, 5, 4, 3, 2, 1, 0]
)
trace2 = go.Scatter(
x=[0, 1, 2, 3, 4, 5, 6, 7, 8],
y=[0, 1, 2, 3, 4, 5, 6, 7, 8]
)
data = [trace1, trace2]
fig1 = go.Figure(data=data, layout=layout)
fig2 = go.Figure(data=data, layout=layout)
fig3 = go.Figure(data=data, layout=layout)
fig4 = go.Figure(data=data, layout=layout)

现在我想制作一个子图,并将每个图形添加到它的象限中:
from plotly import tools
fig = tools.make_subplots(rows=2, cols=2)

但我没有看到任何 fig.append_fig()方法,只有一个 append_trace()方法。有没有简单的方法可以将图形放入 plot.ly 中的子图中?

最佳答案

我想 fig['data'] += data可以帮助。

import plotly.plotly as py
import plotly.graph_objs as go

x1 = [0, 1, 2, 3, 4, 5, 6, 7, 8]
y1 = [8, 7, 6, 5, 4, 3, 2, 1, 0]
x2 = [0, 1, 2, 3, 4, 5, 6, 7, 8]
y2 = [0, 1, 2, 3, 4, 5, 6, 7, 8]

data1 = [go.Scatter(x=x1, y=y1), go.Scatter(x=x2, y=y2)]
data2 = [go.Scatter(x=x1, y=y1, xaxis='x2', yaxis='y2'), go.Scatter(x=x2, y=y2, xaxis='x2', yaxis='y2')]
data3 = [go.Scatter(x=x1, y=y1, xaxis='x3', yaxis='y3'), go.Scatter(x=x2, y=y2, xaxis='x3', yaxis='y3')]
data4 = [go.Scatter(x=x1, y=y1, xaxis='x4', yaxis='y4'), go.Scatter(x=x2, y=y2, xaxis='x4', yaxis='y4')]

from plotly import tools
fig = tools.make_subplots(rows=2, cols=2)
fig['data'] += data1
fig['data'] += data2
fig['data'] += data3
fig['data'] += data4
py.plot(fig, filename = 'basic-line')

关于python - 用 Python 中的多个 plot.ly 图形绘制图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42096172/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com