Plotly.py: tools.make_subplots titles don't respect row_width/column_width

Created on 19 Oct 2018  路  3Comments  路  Source: plotly/plotly.py

The plotly.tools.make_subplots function supports adding titles to subplots by carefully placing annotations. make_subplots also supports a row_width /column_width parameter to specify non-uniform subplot widths/heights.

But it looks like the subplot title placing logic does not take row_width /column_width into account:

row_width:

from plotly import tools
import plotly.plotly as py
import plotly.graph_objs as go

trace1 = go.Scatter(
    x=[0, 1, 2],
    y=[10, 11, 12]
)
trace2 = go.Scatter(
    x=[2, 3, 4],
    y=[100, 110, 120],
)
trace3 = go.Scatter(
    x=[3, 4, 5],
    y=[1000, 1100, 1200],
)
fig = tools.make_subplots(rows=3, cols=1,
                          shared_xaxes=True,
                          vertical_spacing=0.1,
                          subplot_titles=('subtitle 1', 'subtitle 2', 'subtitle 3'),
                          row_width=[0.2, 0.4, 0.2]
                         )

fig.append_trace(trace1, 3, 1)
fig.append_trace(trace2, 2, 1)
fig.append_trace(trace3, 1, 1)

fig['layout'].update(height=600, width=600, title='Subplots with Shared X-Axes')
go.FigureWidget(fig)

newplot 23

column_width:

from plotly import tools
import plotly.plotly as py
import plotly.graph_objs as go

trace1 = go.Scatter(
    x=[0, 1, 2],
    y=[10, 11, 12]
)
trace2 = go.Scatter(
    x=[2, 3, 4],
    y=[100, 110, 120],
)
trace3 = go.Scatter(
    x=[3, 4, 5],
    y=[1000, 1100, 1200],
)
fig = tools.make_subplots(rows=1, cols=3,
                          shared_xaxes=True,
                          vertical_spacing=0.1,
                          subplot_titles=('subtitle 1', 'subtitle 2', 'subtitle 3'),
                          column_width=[0.2, 0.4, 0.2]
                         )

fig.append_trace(trace1, 1, 3)
fig.append_trace(trace2, 1, 2)
fig.append_trace(trace3, 1, 1)

fig['layout'].update(height=600, width=600, title='Subplots with Shared X-Axes')
go.FigureWidget(fig)

newplot 24

bug make_subplots

All 3 comments

From @Kully's comment in #896

plotly.figure_factory.utils.annotation_dict_for_label needs to use horizontal_spacing/vertical_spacing for calculations on where to draw labels for a subplot.

I'll make a PR for this.

Done in #1245 and will be released in 3.4.0. Great work @Kully!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EmilienDupont picture EmilienDupont  路  4Comments

ivirshup picture ivirshup  路  3Comments

aplowman picture aplowman  路  3Comments

eshort0401 picture eshort0401  路  4Comments

binaryfunt picture binaryfunt  路  5Comments