[英]How to plot figures side by side in plotly Dash?
以下链接提供 plot 的代码 plotly 中的图表与 html 组件并排。 但是,我正在寻找类似的功能,例如plt.subplot
的 plt.subplot。 下图取自 matplotlib 的官方文档,是所需 output 的示例。
使用plotly中的插图,您可以并排设置两个图,在 Layout 组件中指定domain
参数,即
import plotly.graph_objs as go
go.Layout(xaxis = dict(domain = [0.0, 0.45]),
xaxis2 = dict(domain = [0.55, 1.0]),
)
您可以在其中调整图中 x 轴的 position 在 0 和 1 之间切换值。完整示例,请参见下面的部分。
以 plot 为例,散点图 plot与条形图并排,
# Set plotly in offline mode
import plotly.graph_objs as go
import pandas as pd
offline.init_notebook_mode(connected=True)
# Simple Scatter plot
trace0 = go.Scatter(x = [10, 20, 30],
y = [40, 30, 20]
)
# Simple Bar chart
trace1 = go.Bar(x=['cat_1', 'cat_2', 'cat_3', 'cat_4'],
y=[5, 27, 31, 48],
xaxis='x2',
yaxis='y2'
)
# Data component
data = [trace0, trace1]
# Layout component
layout = go.Layout(xaxis = dict(domain = [0.0, 0.45]),
xaxis2 = dict(domain = [0.55, 1.0]),
yaxis2 = dict(overlaying='y',
anchor = 'free',
position = 0.55
)
)
# Figure component
fig = go.Figure(data=data, layout=layout)
offline.iplot(fig)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.