如何在绘图仪表板中并排绘制图形?

问题描述 投票:0回答:1

以下link提供了与html组件并排绘制图表的代码。但是,我正在寻找类似的功能,例如matplotlib的plt.subplot。下图取自matplotlib的plt.subplot,是所需输出的示例。

official documentation

python matplotlib plotly data-visualization
1个回答
0
投票

我发现使用enter image description here时,您可以并排设置两个图,在图的轴上指定inset plots自变量。因此,类似于domainplt.subplot(nrows=1, ncols=2)还允许您指定围绕[[x轴和y轴的图的位置。对于plotly的离线模式,下面的代码输出一个散点图,并与一个条形图并排显示,如下图。

domain
# 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)
© www.soinside.com 2019 - 2024. All rights reserved.