Plotly.py: Can't add subplot titles/horizontal spacing to 3d subplots

Created on 14 Jul 2016  路  5Comments  路  Source: plotly/plotly.py

I've got this:

fig = tools.make_subplots(
    rows = 2,
    cols = 2,
    specs = [
        [{'is_3d': True}, {'is_3d': True}],
        [{'is_3d': True}, {'is_3d': True}]
    ],
    horizontal_spacing = 0.001,
    vertical_spacing = 0.000001
)

and I'm unable to add this:

subplot_titles = ('title1', 'title2', 'title3', 'title4'),

I'm running 1.12.3. Here's the error when I try to add _just_ one title, and it's the same if I do four:

Traceback (most recent call last):
  File "wildhorsesbf.py", line 514, in <module>
    subplot_titles = ('srbfb'),
  File "C:\Python27\lib\site-packages\plotly\tools.py", line 1312, in make_subplots
    plot_titles.append({'y': subtitle_pos_y[index],
IndexError: list index out of range
bug make_subplots

Most helpful comment

@Xirious I just ran into this issue and used a quick (hack-y) workaround based on the insight from @Galadirith. Since subplot titles are generated as annotations, creating an equivalent figure without 3D subplots and then copying the annotations into the target figure seems to work. Don't know about solving the spacing issue.

Modifying the 3D-subplots example (https://plot.ly/python/3d-subplots/):

~~~~
fig = tools.make_subplots(rows=2, cols=2,
specs=[[{'is_3d': True}, {'is_3d': True}],
[{'is_3d': True}, {'is_3d': True}]])

annotations = tools.make_subplots(rows=2, cols=2,
subplot_titles=('Plot 1', 'Plot 2', 'Plot 3', 'Plot 4')
)['layout']['annotations']

fig['layout'].update(annotations=annotations)
~~~~

newplot (1)

All 5 comments

I am running into this error on my machine as well even without the spacing arguments.

fig = tools.make_subplots(
    rows = 2,
    cols = 2,
    specs = [
        [{'is_3d': True}, {'is_3d': True}],
        [{'is_3d': True}, {'is_3d': True}]
    ]
)

@jjc12 @eulerreich I have a hacky workaround, add the kwarg shared_xaxes=True.

It doesn't actually make the xaxis shared (I don't know if that is even possible in 3D) but does get rid of the error and make the titles appear for me.

This issue comes from this block of code (plotly/tools.py#L1225-L1235), so I figured if I could make it take the other conditional path it might work and it did.

My guess is that for 3D plots the list_of_domains is not ever populated. There seems to be a way to avoid using the make_subplots method (https://plot.ly/python/subplots/#multiple-subplots). In that example its for 2D plots but I guess you could to the same for 3D plots. The make_subplots adds a fig['annotations'] entry on plotly/tools.py#L1267, so I guess in theory you could manually add the titles, but thats probably quite fiddly.

I hope this workaround works for you 馃槃

As for version 3.5.0, the workaround from @Galadirith sadly does not work anymore

Is there a new workaround? I'm running into this bug right now.

@Xirious I just ran into this issue and used a quick (hack-y) workaround based on the insight from @Galadirith. Since subplot titles are generated as annotations, creating an equivalent figure without 3D subplots and then copying the annotations into the target figure seems to work. Don't know about solving the spacing issue.

Modifying the 3D-subplots example (https://plot.ly/python/3d-subplots/):

~~~~
fig = tools.make_subplots(rows=2, cols=2,
specs=[[{'is_3d': True}, {'is_3d': True}],
[{'is_3d': True}, {'is_3d': True}]])

annotations = tools.make_subplots(rows=2, cols=2,
subplot_titles=('Plot 1', 'Plot 2', 'Plot 3', 'Plot 4')
)['layout']['annotations']

fig['layout'].update(annotations=annotations)
~~~~

newplot (1)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vlizanae picture vlizanae  路  4Comments

hiramf picture hiramf  路  5Comments

suciokhan picture suciokhan  路  3Comments

aplowman picture aplowman  路  3Comments

AmazingSean picture AmazingSean  路  4Comments