Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Subplot fails with empty rowspan at the end

Here is a minimal code to reproduce:

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

trace1 = 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=5, cols=1, specs=[
                                                    [{'rowspan': 3}],
                                                    [{'rowspan': 2}],
fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 4, 1)

fig['layout'].update(title='Stacked, Multirow Subplots with Shared X-Axes')


$ python
This is the format of your plot grid:
[ (1,1) x1,y1 ]
[ (4,1) x1,y2 ]

Traceback (most recent call last):
  File "", line 27, in <module>
    fig.append_trace(trace1, 1, 1)
  File "/home/user/.pyenv/versions/pypy/site-packages/plotly/graph_objs/", line 1263, in append_trace
    .format(r=row, c=col))
Exception: Something went wrong. An axis object for (1,1) subplot cell got deleted.

The code at fails to get fig[‘layout’][‘xaxis1’] which is not existent.

As a workaround, adding:

fig['layout']['xaxis1'].update({'anchor': 'free', 'position': 0.0})

before append_trace calls prevents the exception to be generated.