plotly package — 6.6.0 documentation

Return an instance of plotly.graph_objects.Figure with the subplots domain set in ‘layout’.

Example 1: # stack two subplots vertically fig = tools.make_subplots(rows=2)

This is the format of your plot grid: [ (1,1) x1,y1 ] [ (2,1) x2,y2 ]

fig[‘data’] += [Scatter(x=[1,2,3], y=[2,1,2])] fig[‘data’] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis=’x2’, yaxis=’y2’)]

# or see Figure.add_trace

Example 2: # subplots with shared x axes fig = tools.make_subplots(rows=2, shared_xaxes=True)

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

fig[‘data’] += [Scatter(x=[1,2,3], y=[2,1,2])] fig[‘data’] += [Scatter(x=[1,2,3], y=[2,1,2], yaxis=’y2’)]

Example 3: # irregular subplot layout (more examples below under ‘specs’) fig = tools.make_subplots(rows=2, cols=2,

specs=[[{}, {}],

[{‘colspan’: 2}, None]])

This is the format of your plot grid! [ (1,1) x1,y1 ] [ (1,2) x2,y2 ] [ (2,1) x3,y3 - ]

fig[‘data’] += [Scatter(x=[1,2,3], y=[2,1,2])] fig[‘data’] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis=’x2’, yaxis=’y2’)] fig[‘data’] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis=’x3’, yaxis=’y3’)]

Example 4: # insets fig = tools.make_subplots(insets=[{‘cell’: (1,1), ‘l’: 0.7, ‘b’: 0.3}])

This is the format of your plot grid! [ (1,1) x1,y1 ]

With insets: [ x2,y2 ] over [ (1,1) x1,y1 ]

fig[‘data’] += [Scatter(x=[1,2,3], y=[2,1,2])] fig[‘data’] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis=’x2’, yaxis=’y2’)]

Example 5: # include subplot titles fig = tools.make_subplots(rows=2, subplot_titles=(‘Plot 1’,’Plot 2’))

This is the format of your plot grid: [ (1,1) x1,y1 ] [ (2,1) x2,y2 ]

fig[‘data’] += [Scatter(x=[1,2,3], y=[2,1,2])] fig[‘data’] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis=’x2’, yaxis=’y2’)]

Example 6: # Include subplot title on one plot (but not all) fig = tools.make_subplots(insets=[{‘cell’: (1,1), ‘l’: 0.7, ‘b’: 0.3}],

subplot_titles=(‘’,’Inset’))

This is the format of your plot grid! [ (1,1) x1,y1 ]

With insets: [ x2,y2 ] over [ (1,1) x1,y1 ]

fig[‘data’] += [Scatter(x=[1,2,3], y=[2,1,2])] fig[‘data’] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis=’x2’, yaxis=’y2’)]

Keywords arguments with constant defaults:

rows (kwarg, int greater than 0, default=1):

Number of rows in the subplot grid.

cols (kwarg, int greater than 0, default=1):

Number of columns in the subplot grid.

shared_xaxes (kwarg, boolean or list, default=False)

Assign shared x axes. If True, subplots in the same grid column have one common shared x-axis at the bottom of the gird.

To assign shared x axes per subplot grid cell (see ‘specs’), send list (or list of lists, one list per shared x axis) of cell index tuples.

shared_yaxes (kwarg, boolean or list, default=False)

Assign shared y axes. If True, subplots in the same grid row have one common shared y-axis on the left-hand side of the gird.

To assign shared y axes per subplot grid cell (see ‘specs’), send list (or list of lists, one list per shared y axis) of cell index tuples.

start_cell (kwarg, ‘bottom-left’ or ‘top-left’, default=’top-left’)

Choose the starting cell in the subplot grid used to set the domains of the subplots.

print_grid (kwarg, boolean, default=True):

If True, prints a tab-delimited string representation of your plot grid.

Keyword arguments with variable defaults:

horizontal_spacing (kwarg, float in [0,1], default=0.2 / cols):

Space between subplot columns. Applies to all columns (use ‘specs’ subplot-dependents spacing)

vertical_spacing (kwarg, float in [0,1], default=0.3 / rows):

Space between subplot rows. Applies to all rows (use ‘specs’ subplot-dependents spacing)

subplot_titles (kwarg, list of strings, default=empty list):

Title of each subplot. “” can be included in the list if no subplot title is desired in that space so that the titles are properly indexed.

specs (kwarg, list of lists of dictionaries):

Subplot specifications.

ex1: specs=[[{}, {}], [{‘colspan’: 2}, None]]

ex2: specs=[[{‘rowspan’: 2}, {}], [None, {}]]

  • Indices of the outer list correspond to subplot grid rows starting from the bottom. The number of rows in ‘specs’ must be equal to ‘rows’.

  • Indices of the inner lists correspond to subplot grid columns starting from the left. The number of columns in ‘specs’ must be equal to ‘cols’.

  • Each item in the ‘specs’ list corresponds to one subplot in a subplot grid. (N.B. The subplot grid has exactly ‘rows’ times ‘cols’ cells.)

  • Use None for blank a subplot cell (or to move pass a col/row span).

  • Note that specs[0][0] has the specs of the ‘start_cell’ subplot.

  • Each item in ‘specs’ is a dictionary.

    The available keys are:

    • is_3d (boolean, default=False): flag for 3d scenes

    • colspan (int, default=1): number of subplot columns

      for this subplot to span.

    • rowspan (int, default=1): number of subplot rows

      for this subplot to span.

    • l (float, default=0.0): padding left of cell

    • r (float, default=0.0): padding right of cell

    • t (float, default=0.0): padding right of cell

    • b (float, default=0.0): padding bottom of cell

  • Use ‘horizontal_spacing’ and ‘vertical_spacing’ to adjust the spacing in between the subplots.

insets (kwarg, list of dictionaries):

Inset specifications.

  • Each item in ‘insets’ is a dictionary.

    The available keys are:

    • cell (tuple, default=(1,1)): (row, col) index of the

      subplot cell to overlay inset axes onto.

    • is_3d (boolean, default=False): flag for 3d scenes

    • l (float, default=0.0): padding left of inset

      in fraction of cell width

    • w (float or ‘to_end’, default=’to_end’) inset width

      in fraction of cell width (‘to_end’: to cell right edge)

    • b (float, default=0.0): padding bottom of inset

      in fraction of cell height

    • h (float or ‘to_end’, default=’to_end’) inset height

      in fraction of cell height (‘to_end’: to cell top edge)

column_width (kwarg, list of numbers)

Column_width specifications

  • Functions similarly to column_width of plotly.graph_objects.Table. Specify a list that contains numbers where the amount of numbers in the list is equal to cols.

  • The numbers in the list indicate the proportions that each column domains take across the full horizontal domain excluding padding.

  • For example, if columns_width=[3, 1], horizontal_spacing=0, and cols=2, the domains for each column would be [0. 0.75] and [0.75, 1]

row_width (kwargs, list of numbers)

Row_width specifications

  • Functions similarly to column_width. Specify a list that contains numbers where the amount of numbers in the list is equal to rows.

  • The numbers in the list indicate the proportions that each row domains take along the full vertical domain excluding padding.

  • For example, if row_width=[3, 1], vertical_spacing=0, and cols=2, the domains for each row from top to botton would be [0. 0.75] and [0.75, 1]