Skip to content

Commit 421dd5f

Browse files
committed
improve make_subplots docstring
1 parent 2edb810 commit 421dd5f

File tree

1 file changed

+62
-37
lines changed

1 file changed

+62
-37
lines changed

plotly/tools.py

Lines changed: 62 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -499,58 +499,76 @@ def make_subplots(rows=1, cols=1,
499499
with the subplots domain set in 'layout'.
500500
501501
Example 1:
502-
# stack two subplots vertically
503-
fig = tools.get_subplots(rows=2)
504-
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x1', yaxis='y1')]
505-
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')]
502+
# stack two subplots vertically
503+
>>> fig = tools.make_subplots(rows=2, print_grid=True)
504+
This is the format of your plot grid!
505+
[ (1,1) x1,y1 ]
506+
[ (2,1) x2,y2 ]
507+
508+
>>> fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x1', yaxis='y1')]
509+
>>> fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')]
506510
507511
Example 2:
508-
# subplots with shared x axes
509-
fig = tools.get_subplots(rows=2, shared_xaxes=True)
510-
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], yaxis='y1')]
511-
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], yaxis='y2')]
512+
# subplots with shared x axes
513+
>>> fig = tools.make_subplots(rows=2, shared_xaxes=True, print_grid=True)
514+
515+
TODO What's the default behavior here??
516+
517+
>>> fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], yaxis='y1')]
518+
>>> fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], yaxis='y2')]
512519
513520
Example 3:
514-
# irregular subplot layout
515-
fig = tools.get_subplots(rows=2, columns=2,
516-
specs=[[{}, {}], [{'colspan': 2}]])
517-
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x1', yaxis='y1')]
518-
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')]
519-
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x3', yaxis='y3')]
521+
# irregular subplot layout (more examples below under 'specs')
522+
>>> fig = tools.make_subplots(rows=2, cols=2,
523+
specs=[[{}, {}],
524+
[{'colspan': 2}, None]],
525+
print_grid=True)
526+
This is the format of your plot grid!
527+
[ (1,1) x1,y1 ] [ (1,2) x2,y2 ]
528+
[ (2,1) x3,y3 - ]
529+
530+
>>> fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x1', yaxis='y1')]
531+
>>> fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')]
532+
>>> fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x3', yaxis='y3')]
520533
521534
Example 4:
522-
# insets
523-
fig = tools.get_subplots(insets=[{'cell':(0,0), 'l': 0.7, 'b': 0.3}])
524-
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2])]
525-
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')]
535+
# insets
536+
>>> fig = tools.make_subplots(insets=[{'cell': (1,1), 'l': 0.7, 'b': 0.3}],
537+
print_grid=True)
538+
This is the format of your plot grid!
539+
[ (1,1) x1,y1 ]
526540
527-
Example 5:
528-
# print out string showing the subplot grid you've put in the layout
529-
fig = tools.get_subplots(rows=3, columns=2, print_grid=True)
541+
With insets:
542+
[ x2,y2 ] over [ (1,1) x1,y1 ]
543+
544+
>>> fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2])]
545+
>>> fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')]
530546
531547
Keywords arguments with constant defaults:
532548
533549
rows (kwarg, int, default=1):
534-
Number of rows on the figure.
550+
Number of rows in the subplot grid.
535551
536-
columns (kwarg, int, default=1):
537-
Number of columns on the figure.
552+
cols (kwarg, int, default=1):
553+
Number of columns in the subplot grid.
538554
539555
shared_xaxes (kwarg, boolean or list, default=False)
540556
Assign shared x axes.
541557
If True, all x axes are shared.
558+
542559
To assign shared x axes per subplot grid cell (see 'specs'),
543560
send list (or list of lists, one list per shared axis)
544561
of cell index tuples.
545562
546563
shared_yaxes (kwarg, boolean or list, default=False)
547564
Assign shared y axes.
548565
If True, all y axes are shared.
566+
549567
To assign shared y axes per subplot grid cell (see 'specs'),
550568
send list (or list of lists, one list per shared axis)
551569
of cell index tuples.
552570
553-
start_cell (kwarg, 'bottom-left' or 'top-left', default='bottom-left')
571+
start_cell (kwarg, 'bottom-left' or 'top-left', default='top-left')
554572
Choose the starting cell in the subplot grid used to set the
555573
domains of the subplots.
556574
@@ -560,54 +578,61 @@ def make_subplots(rows=1, cols=1,
560578
561579
Keyword arguments with variable defaults:
562580
563-
horizontal_spacing (kwarg, float in [0,1], default=0.2 / columns):
581+
horizontal_spacing (kwarg, float in [0,1], default=0.2 / cols):
564582
Space between subplot columns.
565-
566583
Applies to all columns (use 'specs' subplot-dependents spacing)
567584
568585
vertical_spacing (kwarg, float in [0,1], default=0.3 / rows):
569586
Space between subplot rows.
570587
Applies to all rows (use 'specs' subplot-dependents spacing)
571588
572-
specs (kwarg, list (of lists) of dictionaries):
589+
specs (kwarg, list of lists of dictionaries):
573590
Subplot specifications.
574591
592+
ex1: specs=[[{}, {}], [{'colspan': 2}, None]]
593+
594+
ex2: specs=[[{'rowspan': 2}, {}], [None, {}]]
595+
575596
- Indices of the outer list correspond to subplot grid rows
576597
starting from the bottom. The number of rows in 'specs'
577598
must be equal to 'rows'.
578599
579600
- Indices of the inner lists correspond to subplot grid columns
580601
starting from the left. The number of columns in 'specs'
581-
must be equal to 'columns'.
602+
must be equal to 'cols'.
582603
583604
- Each item in the 'specs' list corresponds to one subplot
584-
in a subplot grid. The subplot grid has exactly 'rows'
585-
times 'columns' cells.
605+
in a subplot grid. (N.B. The subplot grid has exactly 'rows'
606+
times 'cols' cells.)
586607
587608
- Use None for blank a subplot cell (or to move pass a col/row span).
588609
589-
- Note that specs[0][0] has the specs for the bottom-left subplot
610+
- Note that specs[0][0] has the specs of the 'start_cell' subplot.
590611
591612
- Each item in 'specs' is a dictionary.
592613
The available keys are:
593614
594615
* is_3d (boolean, default=False): flag for 3d scenes
595-
* colspan (int, default=1): span across grid columns
596-
from left to right
597-
* rowspan (int, default=1): span across grid rows
598-
from bottom to top
616+
* colspan (int, default=1): number of subplot columns
617+
for this subplot to span.
618+
* rowspan (int, default=1): number of subplot rows
619+
for this subplot to span.
599620
* l (float, default=0.0): padding left of cell
600621
* r (float, default=0.0): padding right of cell
601622
* t (float, default=0.0): padding right of cell
602623
* b (float, default=0.0): padding bottom of cell
603624
625+
- Use 'horizontal_spacing' and 'vertical_spacing' to adjust
626+
the spacing in between the subplots.
627+
604628
insets (kwarg, list of dictionaries):
605629
Inset specifications.
606630
607631
- Each item in 'insets' is a dictionary.
608632
The available keys are:
609633
610-
* cell (tuple, default=(0,0)) subplot cell indices
634+
* cell (tuple, default=(1,1)): (row, col) index of the
635+
subplot cell to overlay inset axes onto.
611636
* is_3d (boolean, default=False): flag for 3d scenes
612637
* l (float, default=0.0): padding left of inset
613638
in fraction of cell width

0 commit comments

Comments
 (0)