Skip to content
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

Cannot set x-axis to side='top' for second chart in subplot with shared_yaxes=True #1553

Closed
kasparthommen opened this issue May 6, 2019 · 3 comments

Comments

@kasparthommen
Copy link

kasparthommen commented May 6, 2019

Hi all,

I'm trying to display two charts with shared y-axes side-by side and with their respective x-axes shown at the top. This works for the 1st chart on the left, but not for the 2nd one on the right, see the minimal example below. Am I doing something wrong or is this a bug?

Note that it works fine if I change shared_yaxes to False but I really need them shared.

import plotly.plotly as py
import plotly.graph_objs as go
from plotly import tools
from plotly.offline import init_notebook_mode, iplot

init_notebook_mode()

trace_left = go.Scatter(x=[3, 2, 5], y=[1, 2, 3], name='Left')
trace_right = go.Scatter(x=[2, 6, 7], y=[1, 2, 4], name='Right')

fig = tools.make_subplots(rows=1, cols=2, specs=[[{}, {}]], shared_yaxes=True)
fig.append_trace(trace_left, 1, 1)
fig.append_trace(trace_right, 1, 2)

layout = go.Layout(
    xaxis=dict(side='top'),
    xaxis2=dict(side='top'),   # <- 2nd x-axis should be on top as well but isn't
)

fig['layout'].update(layout)
iplot(fig, filename='issue')

06-05-2019 15-55-36

@jonmmease
Copy link
Contributor

Hi @kasparthommen,

Thanks for the report. I'm not exactly sure what's going wrong with the current version of make_subplots, but the new make_subplots version that will be the default in plotly.py version 4 (See #1528) seems to behave as you would expect. You can try this out now using the v4_subplots future flag. For example:

from _plotly_future_ import v4_subplots
import plotly.graph_objs as go
from plotly import tools
from plotly.offline import init_notebook_mode, iplot

init_notebook_mode()

trace_left = go.Scatter(x=[3, 2, 5], y=[1, 2, 3], name='Left')
trace_right = go.Scatter(x=[2, 6, 7], y=[1, 2, 4], name='Right')

fig = tools.make_subplots(rows=1, cols=2, specs=[[{}, {}]], shared_yaxes=True)
fig.append_trace(trace_left, 1, 1)
fig.append_trace(trace_right, 1, 2)

layout = go.Layout(
    xaxis=dict(side='top'),
    xaxis2=dict(side='top'),   # <- 2nd x-axis should be on top as well but isn't
)

fig['layout'].update(layout)
iplot(fig, filename='issue')

newplot-14

You can also make this a little bit more concise using the update_xaxes method added in version 3.9 (See #1548).

from _plotly_future_ import v4_subplots
import plotly.graph_objs as go
from plotly import tools
from plotly.offline import init_notebook_mode, iplot

init_notebook_mode()

trace_left = go.Scatter(x=[3, 2, 5], y=[1, 2, 3], name='Left')
trace_right = go.Scatter(x=[2, 6, 7], y=[1, 2, 4], name='Right')

fig = tools.make_subplots(
    rows=1,
    cols=2,
    shared_yaxes=True
).update_xaxes(side='top')

fig.append_trace(trace_left, 1, 1)
fig.append_trace(trace_right, 1, 2)

iplot(fig, filename='issue')

@kasparthommen
Copy link
Author

kasparthommen commented May 17, 2019

Hi @jonmmease

Thanks for your reply, I'll try that!

I assume this means that there won't be a fix for the current version? If so then please feel free to mark this issue as closed/wont-fix or whatever you see fit, thanks.

@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

3 participants