python - 如何在 plotly python 中嵌套数字?
问题描述
我想把一些数字放在另一个图中。目标是这样的:
注意:我不想要一个带有 2 x 2 子图的图形。相反,我想要一个带有 1 x 2 子图的图形,每个子图都由一个具有 2 x 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")
我怎样才能做到这一点?
解决方案
推荐阅读
- java - While 循环不退出或不显示结果
- javascript - 如何重构函数参数及其用法
- keyboard-shortcuts - ag-grid上下文菜单快捷键不起作用
- java - 无法使用 Java SDK 将文件上传到 OneDrive
- flutter - 在 Flutter/Dart 中有效解析 JSON
- python - 查找最大数字时出现 Python 错误
- c# - 如何从多个位置标签内有多个 appSettings 标签的配置文件中读取 appSettings?
- angular - 单点登录 - 跨域身份验证 (@auth0/angular2-jwt)
- c - 驱动程序开发(Windows):什么是 RTL?
- vba - 如何使用 VBA 将字符串值设置为 MS-Word 中 ContentControl DatePicker 中的日期值