question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't add subplot titles/horizontal spacing to 3d subplots

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

3reactions
gabehopecommented, Apr 12, 2019

@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)

3reactions
Galadirithcommented, Apr 11, 2017

@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 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Improve subplot size/spacing with many subplots
No matter how big I allow the figure to be, the subplots always seem to overlap. My code currently looks like import matplotlib.pyplot...
Read more >
2D and 3D axes in same figure - Matplotlib
This example shows a how to plot a 2D and 3D plot on the same figure. A tale of 2 subplots. import matplotlib.pyplot...
Read more >
plotly.subplots.make_subplots — 5.11.0 documentation
Space between subplot columns in normalized plot coordinates. ... (default None)) – Title to place below the bottom row of subplots, centered horizontally....
Read more >
How to set the spacing between subplots in Matplotlib in ...
Using tight_layout() method to set the spacing between subplots. The tight_layout() method automatically maintains the proper space between ...
Read more >
matplotlib - 2D and 3D plotting in Python
This line configures matplotlib to show figures embedded in the notebook, # instead of opening a new window for each figure. More about...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found