Skip to content

Add support in make_subplots for mutiple axes #1544

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
marcotama opened this issue May 2, 2019 · 7 comments
Closed

Add support in make_subplots for mutiple axes #1544

marcotama opened this issue May 2, 2019 · 7 comments
Milestone

Comments

@marcotama
Copy link

Hi, this is a feature request, not a bug, so I do not have a minimum example.

My use case is that I have been using make_suplots (to generate a quite simple 2x2 layout), and I would now introduce a second y axis in each subplot, in order to obtain the same effect described here: https://plot.ly/python/multiple-axes/

I could not find a way to do this through make_subplots, but I seem to understand that it is possible by setting the layout. My issue with this approach is that I am afraid to lose some "magic" that is happening in make_subplots.

Can you advise how to proceed? Is it something you are willing to implement?

@jonmmease
Copy link
Contributor

Hi @marcotama,

Yeah, multiple y-axes in subplots is something we've been thinking about for version 4, but we haven't settled on an API yet. My current thinking is to add a new option to elements of the specs argument to make_subplots. Something like

from plotly.tools import make_subplots
fig = make_subplots(
    2, 2, specs=[[{'secondary_y': True}, {'secondary_y': True}],
                 [{'secondary_y': True}, {'secondary_y': True}]])

fig.add_trace(go.Scatter(...), row=1, col=1)
fig.add_trace(go.Scatter(...), row=1, col=1, secondary_y=True)

It's admittedly a little clunky, but it would get the job done without too much added API complexity. What do you think? cc @nicolaskruchten @chriddyp

@marcotama
Copy link
Author

marcotama commented May 3, 2019

Hi @jonmmease,

It looks simple enough to use.
My only doubt is, does that mean if I pass 'secondary_y': True, the y axis "counter" increments by 2 instead of 1? Would it be possible to return, or have a helper function to retrieve, the axis names? Something like

from plotly.tools import make_subplots
fig, ax_info = make_subplots(
    2, 2, specs=[[{'secondary_y': True}, {}],
                 [{'secondary_x': True}, {'secondary_y': True}]])
print(ax_info)
>>> [[('x','y','y2'),('x2','y3')],[('x3','x4','y4'),('x5','y5','y6')]]

I know this can be figured out manually, but I fear it is fertile ground for bugs, especially in more complex setups.

Edit: funnily enough, I made a mistake with counting axes while writing the above example.

@jonmmease
Copy link
Contributor

We would at least add the second y-axis label to the fig.print_grid() output. Would that be enough or do you have use cases in mind where you want programmatic access to the y-axis labels?

This info is all in the internal fig._grid_ref property, but it's not directly exposed in the API right now except through fig.print_grid.

@marcotama
Copy link
Author

I think print_grid is good enough. Thanks!

@jonmmease jonmmease added this to the v3.10 milestone May 9, 2019
@jonmmease
Copy link
Contributor

Hi @marcotama,

I'd appreciate your feedback on #1564 if you have a chance to take a look and give it a spin. Installation instructions at #1564 (comment)

@marcotama
Copy link
Author

Hi @jonmmease , I left a comment on the PR page. Apologies for the late reply, I have been busy!

@jonmmease
Copy link
Contributor

Done in #1564

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

2 participants