45

I have a a large space in between my subplots in plotly. In matplotlib, there is a layout called a tight layout that removes this. Is there any similar layout in plotly? I am plotting in an iPython notebook so there is limited space. See the space in the image below.

enter image description here

pr338
  • 8,730
  • 19
  • 52
  • 71

1 Answers1

73

Yes there is! You can use specs and vertical_spacing or horizontal_spacing. Here is an example for horizontal_spacing:

from plotly import tools
import plotly.plotly as py
from plotly.graph_objs import *

trace1 = Scatter(
     x=[1, 2, 3],
     y=[4, 5, 6]
)
trace2 = Scatter(
     x=[20, 30, 40],
     y=[50, 60, 70],
)

fig = tools.make_subplots(rows = 1, cols = 2, specs = [[{}, {}]],
                          horizontal_spacing = 0.05)

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

py.iplot(fig, filename='make-subplot-horizontal_spacing')

here is the plot

You can find more tutorials on Plotly subplots page: Plotly subplots tutorial

neda
  • 909
  • 7
  • 4
  • 5
    The details of specs aren't clear. Is there a docs page on it explaining it in more detail? – wordsforthewise Jun 23 '17 at 21:41
  • 3
    Negative. I'm sure there is something somewhere, but plotly's docs are not easy to find/navigate from what I recall. – wordsforthewise Nov 14 '19 at 17:40
  • 1
    `tools.make_subplots()` is now deprecated. You can obtain the same results with `plotly.subplots.make_subplots(rows = rows, cols = cols, horizontal_spacing = 0.05)` – Damien Jan 06 '23 at 09:26