Skip to content

make_subplots(row_width=[]) is parsed in the 'wrong' order #1275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
EBoisseauSierra opened this issue Nov 15, 2018 · 3 comments
Closed

make_subplots(row_width=[]) is parsed in the 'wrong' order #1275

EBoisseauSierra opened this issue Nov 15, 2018 · 3 comments

Comments

@EBoisseauSierra
Copy link

Imagine have 3 subplots stacked one above the other. I want the first (i.e. the top one) to have its height twice as big as the others.
So after I have set:

fig = tools.make_subplots(
      rows=3, 
      cols=1,
      subplot_titles=('subtitle 1', 'subtitle 2', 'subtitle 3'),

… I intuitively set (thanks to @Kully 's previous PR):

      row_width=[2, 1, 1]
)

However, this makes the 3rd graph (i.e. the "first… from last") have its height twice as big as the others:

plot from api 3

I believe that row_width is parsed in the wrong direction.


MWE

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

trace1 = go.Scatter(
    x=[3, 4, 5],
    y=[1000, 1100, 1200],
)
trace3 = go.Scatter(
    x=[0, 1, 2],
    y=[10, 11, 12]
)
trace2 = go.Scatter(
    x=[2, 3, 4],
    y=[100, 110, 120],
)
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=[2, 1, 1]
)

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

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

plot_url = py.plot(fig)
@jonmmease
Copy link
Contributor

Thanks for the report @EBoisseauSierra ,

For sake of discussion, here's the current behavior of the general 2D case where row_width=[2, 1, 1] and column_width=[2, 1].

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

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

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

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

newplot 7

So what's happening is that the row_width and column_width elements correspond to subplots starting from the bottom left. This matches the usual Cartesian coordinate system conventions, but is not consistent with the row/col indexing, which starts from the top left. The subplot_titles property is a 1D list that wraps around the subplots in row-major ordering.

I agree that this is a bit of an inconsistent state of affairs, but it's worked this way for a long time so I don't think we should change the default before the next major version bump (version 4). I'm going to tag this as make_subplots and breaking change so that we remember to come back to it when planning for version 4. In the meantime, you can safely reverse the row_width list and trust that this behavior will hold during all version 3.* releases.

Does that sound reasonable?

@EBoisseauSierra
Copy link
Author

I now better understand how it worked, and get why it wasn't really a "bug".
I still think that it still more intuitive to reverse the order, as it is then consistent with how subplots are assigned traces.

Anyway, I totally get your point — backward compatibility is a big issue. I have no problem waiting for versions 4+, keeping in mind to update my code in due time (-;
In the mean time, I can now change row_width=[ # in reverse order. don't ask why…!

Thanks a lot for responsiveness… and plotly!

@gvwilson
Copy link
Contributor

Hi - we are currently trying to tidy up Plotly's public repositories to help us focus our efforts on things that will help users most. Since this issue has been sitting for several years, I'm going to close it. If it's still a concern, we'd be grateful if you could open a new issue (with a short reproducible example if appropriate) so that we can add it to our backlog. Thanks for your help - @gvwilson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants