Skip to content

subplot_titles posisiong value goes negative when shared axes is True and start_cell is bottom-left  #1002

Description

@rysktky

Hi I just fund code like this does not work as described on the title.
I could not find anything relevant about this.
I am trying to find a workaround, but could there be simple solution?

using python3.6 with fedora 28.
installed plotly with pip.

Regards

sample code
#Added "vertical_spacing=0.00" to simplified the calculation as per plotly.py/plotly/tootls.py

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

trace0 = go.Scatter( x=[1, 2], y=[1, 2])
trace1 = go.Scatter( x=[1, 2], y=[5, 3])
trace2 = go.Scatter( x=[1, 2, 3], y=[2, 1, 2])

fig = tools.make_subplots(rows=3, cols=1, 
                          shared_xaxes=True,
                          start_cell='bottom-left',
                          vertical_spacing=0.00,
                          subplot_titles=('First Subplot','Second Subplot', 'Third Subplot'))

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

fig['layout'].update(showlegend=False, title='Specs with Subplot Title')
py.plot(fig, filename='custom-sized-subplot-with-subplot-titles')

pprint'ed the layout

>>> pprint.pprint(fig['layout'])
{'annotations': [{'font': {'size': 16},
                  'showarrow': False,
                  'text': 'First Subplot',
                  'x': 0.5,
                  'xanchor': 'center',
                  'xref': 'paper',
                  'y': 1.0,     <<<< This is GOOD.
                  'yanchor': 'bottom',
                  'yref': 'paper'},
                 {'font': {'size': 16},
                  'showarrow': False,
                  'text': 'Second Subplot',
                  'x': 0.5,
                  'xanchor': 'center',
                  'xref': 'paper',
                  y': 0.0,     <<< 2nd subplot title is already at ZERO and it is shown on the bottom.
                  'yanchor': 'bottom',
                  'yref': 'paper'},
                 {'font': {'size': 16},
                  'showarrow': False,
                  'text': 'Third Subplot',
                  'x': 0.5,
                  'xanchor': 'center',
                  'xref': 'paper',
                  'y': -1.0,     <<< It has negative value and does not get actually shown.
                  'yanchor': 'bottom',
                  'yref': 'paper'}],
 'xaxis1': {'anchor': 'y1', 'domain': [0.0, 1.0]},
 'yaxis1': {'anchor': 'x1', 'domain': [0.0, 0.3333333333333333]},
 'yaxis2': {'anchor': 'free',
            'domain': [0.3333333333333333, 0.6666666666666666],
            'position': 0.0},
 'yaxis3': {'anchor': 'free',
            'domain': [0.6666666666666666, 1.0],
            'position': 0.0}}

It seems it is coming from this part of plotly.py/plotly/tootls.py

1303     # Add subplot titles
1304 
1305     # If shared_axes is False (default) use list_of_domains
1306     # This is used for insets and irregular layouts
1307     if not shared_xaxes and not shared_yaxes:
1308         x_dom = list_of_domains[::2]
1309         y_dom = list_of_domains[1::2]
1310         subtitle_pos_x = []
1311         subtitle_pos_y = []
1312         for x_domains in x_dom:
1313             subtitle_pos_x.append(sum(x_domains) / 2)
1314         for y_domains in y_dom:
1315             subtitle_pos_y.append(y_domains[1])
1316     # If shared_axes is True the domin of each subplot is not returned so the
1317     # title position must be calculated for each subplot
1318     else:
1319         subtitle_pos_x = [None] * cols
1320         subtitle_pos_y = [None] * rows
1321         delt_x = (x_e - x_s)
1322         for index in range(cols):
1323             subtitle_pos_x[index] = ((delt_x / 2) +
1324                                      ((delt_x + horizontal_spacing) * index))
1325         subtitle_pos_x *= rows
1326         for index in range(rows):
1327             subtitle_pos_y[index] = (1 - ((y_e + vertical_spacing) * index))
1328         subtitle_pos_y *= cols
1329         subtitle_pos_y = sorted(subtitle_pos_y, reverse=True) 

How the result look like
Please remember it has vertical_spacing=0.00. There are 3 subplots stacked vertically here...
newplot

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsomething broken

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions