从Python中的多个plot.ly图形中绘制图形 [英] Make plot out of multiple plot.ly figures in Python

查看:592
本文介绍了从Python中的多个plot.ly图形中绘制图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've made 4 figures in plot.ly, for example:

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)

现在,我想制作一个子图,并将每个图形添加到它的一个象限中:

Now I want to make a subplot, and add each figure to a quadrant of it:

from plotly import tools
fig = tools.make_subplots(rows=2, cols=2)

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

but I don't see any fig.append_fig() method, only an append_trace() method. Is there no easy way to drop in a figure into a subplot in 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中的多个plot.ly图形中绘制图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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