#!/usr/bin/env python # coding: utf-8 # ## 4.1 サブプロット # In[1]: import plotly.graph_objects as go from plotly.subplots import make_subplots line_trace = go.Scatter(x=[0, 1, 2], y=[5, 3, 4], name="line") scatter_trace = go.Scatter( x=[1, 2, 3], y=[2, 1, 5], mode="markers", name="scatter" ) bar_trace = go.Bar(x=[1, 2, 3], y=[1, 2, 3], name="bar") area_trace = go.Scatter( x=[3, 4, 5], y=[5, 3, 4], mode="none", fillcolor="#1f77b4", fill="tozeroy", name="area", ) subplots_fig = make_subplots(rows=2, cols=2) subplots_fig.add_trace(line_trace, row=1, col=1) subplots_fig.add_trace(scatter_trace, row=1, col=2) subplots_fig.add_trace(bar_trace, row=2, col=1) subplots_fig.add_trace(area_trace, row=2, col=2) subplots_fig.show() # In[2]: complex_fig = make_subplots( rows=3, cols=2, # ❶ specs=[ # 1行目 [{}, {"rowspan": 2}], # ❷ 行結合 # 2行目 [{}, None], # 3行目 [{"colspan": 2}, None], # ❸ 列結合 ], shared_xaxes=True, # X軸を共有 column_widths=[0.6, 0.4], # 幅に割り当てる割合を指定 row_heights=[0.4, 0.4, 0.2], # 高さに割り当てる割合を指定 ) complex_fig.add_trace(line_trace, row=1, col=1) complex_fig.add_trace(scatter_trace, row=1, col=2) complex_fig.add_trace(bar_trace, row=2, col=1) complex_fig.add_trace(area_trace, row=3, col=1) complex_fig.show() # In[3]: barpolar_trace = go.Barpolar(theta=[0, 60, 180], r=[6, 5, 3], name="barpolar") pie_trace = go.Pie(values=[30, 60, 10], labels=["a", "b", "c"], name="pie") scatter3d_trace = go.Scatter3d( x=[1, 2, 3], y=[5, 3, 4], z=[2, 5, 1], mode="markers", marker={"size": 2}, name="3D scatter", ) multiple_types_fig = make_subplots( rows=2, cols=2, specs=[ [{"type": "xy"}, {"type": "polar"}], [{"type": "domain"}, {"type": "scene"}], ], ) multiple_types_fig.add_trace(scatter_trace, row=1, col=1) multiple_types_fig.add_trace(barpolar_trace, row=1, col=2) multiple_types_fig.add_trace(pie_trace, row=2, col=1) multiple_types_fig.add_trace(scatter3d_trace, row=2, col=2) multiple_types_fig.show()