plotly.py: tools.make_subplots with colspan/rowspan fails when using sharex/sharey

Hi, i am trying to create subplots with colspan/rowspan attribute and shared_xaxes using the code below (Plotly 3.3). As soon as i use the shared_xaxes=True parameter, the code fails with the error message:

Exception: Something went wrong. An axis object for (2,4) subplot cell got deleted.

Example code:

from plotly import tools
import plotly
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=[2, 3, 4],
    y=[100, 110, 120],
)

fig = tools.make_subplots(rows=3, cols=4, specs=[[{'colspan':3}, None, None, None], 
                                                [{'rowspan':2, 'colspan':3}, None, None, {'rowspan':2}], 
                                                [None, None, None, None]],
                          shared_xaxes=True, shared_yaxes=True,
                          vertical_spacing=0.001)

print(fig['layout'])

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

print(fig['layout'])

fig['layout'].update(height=600, width=600, title='Stacked Subplots with Shared X-Axes')
plotly.offline.iplot(fig, filename='test')

Cheers, Georg

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (1 by maintainers)

Most upvoted comments

@empet Nope. Even adding a vertically aligned subplot+trace does not help:

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


trace1 = go.Scatter(
    x=[0, 1, 2],
    y=[10, 11, 12]
)
trace2 = go.Scatter(
    x=[0, 1, 2],
    y=[100, 110, 120],
)
trace3 = go.Scatter(
    x=[0, 1, 2],
    y=[100, 110, 120],
)
trace4 = go.Scatter(
    x=[0, 1, 2],
    y=[100, 110, 120],
)
trace5 = go.Scatter(
    x=[0, 1, 2],
    y=[100, 110, 120],
)

fig = tools.make_subplots(rows=5, cols=4, specs=[[{'colspan':3}, None, None, None], 
                                                 [{'rowspan':2, 'colspan':3}, None, None, {'rowspan':2}], 
                                                 [None, None, None, None],
                                                 [{'rowspan':2, 'colspan':3}, None, None, {'rowspan':2}], 
                                                 [None, None, None, None],
                                                 ],
                          shared_xaxes=True, shared_yaxes=True,
                          vertical_spacing=0.001)

print(fig['layout'])

fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 2, 1)
fig.append_trace(trace3, 2, 4)
fig.append_trace(trace4, 4, 1)
fig.append_trace(trace5, 4, 4)

print(fig['layout'])

fig['layout'].update(height=600, width=600, title='Stacked Subplots with Shared X-Axes')
plotly.offline.iplot(fig, filename='test')