I want to put some figures inside another figure in plotly. The goal is something like this:
Note: I do NOT want a figure with 2 by 2 subplots. Instead, I want a figure with 1 by 2 subplots, each of which are filled by a figure that has 2 by 1 subplots.
Here is what I have tried:
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")
How can I do this?
