Как мне вложить рисунки в сюжетный питон? - PullRequest
0 голосов
/ 26 июня 2019

Я хочу поместить некоторые фигуры внутри другой фигуры в заговоре. Цель примерно такая:

enter image description here

Примечание: я НЕ хочу фигуру с 2 на 2 субплота. Вместо этого мне нужна фигура с 1 на 2 субплота, каждый из которых заполнен фигурой, которая имеет 2 к 1 субплота.

Вот что я пробовал:

import plotly.offline as py
from plotly import tools
import plotly.graph_objs as go

#Fake data
left_xs = [1, 2, 3, 4, 5]
left_top_ys = [1,4,9,16,25]
left_bot_ys = [0, 0, 0, 50, 0]

right_xs = [1, 2, 3, 4, 5, 6]
right_top_ys = [2, 4, 7, 11, 16, 22]
right_bot_ys = [0, 0, 10, 20, 0 ,0]

left_title = "Left"
right_title = "Right"

#The figure that will contain the sub figures
bigfig = tools.make_subplots(rows=1, cols=2, subplot_titles=[left_title, right_title], vertical_spacing=0.02)

#Left subfigure (in the red circle)
left_fig = tools.make_subplots(rows=2, cols=1, vertical_spacing=0.05, subplot_titles=["left_top", "left_bot"], shared_xaxes=True)
left_fig.append_trace(
    go.Scatter(x=left_xs, y=left_top_ys, name="Left Top", showlegend=False),
    1, 1
    )
left_fig.append_trace(
    go.Scatter(x=left_xs, y=left_bot_ys, name="Left Bot", showlegend=False),
    2, 1
    )

#Right subfigure (in the blue circle)
right_fig = tools.make_subplots(rows=2, cols=1, vertical_spacing=0.05, subplot_titles=["right_top", "right_bot"], shared_xaxes=True)
right_fig.append_trace(
    go.Scatter(x=right_xs, y=right_top_ys, name="right Top", showlegend=False),
    1, 1
    )
right_fig.append_trace(
    go.Scatter(x=right_xs, y=right_bot_ys, name="right Bot", showlegend=False),
    2, 1
    )

#Doesn't work, only puts in the first trace of each fig
#How do I put both the left figure and the right figure in bigfig?
bigfig.append_trace(left_fig.data[0], 1, 1)
bigfig.append_trace(right_fig.data[0], 1, 2)

#Show results
py.plot(bigfig, filename="bigfig.html")
py.plot(left_fig, filename="left_fig.html")
py.plot(right_fig, filename="right_fig.html")

Как я могу это сделать?

...