Skip to content

Commit fc69a05

Browse files
committed
update to add subplot titles
-added some examples to the doc -removed blank annotations to the figure object
1 parent 19ec4b6 commit fc69a05

File tree

1 file changed

+41
-14
lines changed

1 file changed

+41
-14
lines changed

plotly/tools.py

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,31 @@ def make_subplots(rows=1, cols=1,
586586
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2])]
587587
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')]
588588
589+
Example 5:
590+
# include subplot titles
591+
fig = tools.make_subplots(rows=2, subplot_titles=('Plot 1','Plot 2'))
592+
593+
This is the format of your plot grid:
594+
[ (1,1) x1,y1 ]
595+
[ (2,1) x2,y2 ]
596+
597+
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2])]
598+
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')]
599+
600+
Example 6:
601+
# Include subplot title on one plot (but not all)
602+
fig = tools.make_subplots(insets=[{'cell': (1,1), 'l': 0.7, 'b': 0.3}],
603+
subplot_titles=('','Inset'))
604+
605+
This is the format of your plot grid!
606+
[ (1,1) x1,y1 ]
607+
608+
With insets:
609+
[ x2,y2 ] over [ (1,1) x1,y1 ]
610+
611+
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2])]
612+
fig['data'] += [Scatter(x=[1,2,3], y=[2,1,2], xaxis='x2', yaxis='y2')]
613+
589614
Keywords arguments with constant defaults:
590615
591616
rows (kwarg, int greater than 0, default=1):
@@ -632,6 +657,8 @@ def make_subplots(rows=1, cols=1,
632657
633658
subplot_titles (kwarg, list of strings, default=empty list):
634659
Title of each subplot.
660+
"" can be included in the list if no subplot title is desired in
661+
that space so that the titles are properly indexed.
635662
636663
specs (kwarg, list of lists of dictionaries):
637664
Subplot specifications.
@@ -1143,23 +1170,23 @@ def _pad(s, cell_len=cell_len):
11431170
)
11441171

11451172
# Add subplot titles
1146-
if not subplot_titles:
1147-
pass
1148-
else:
1149-
x_dom = list_of_domains[::2]
1150-
y_dom = list_of_domains[1::2]
1173+
x_dom = list_of_domains[::2]
1174+
y_dom = list_of_domains[1::2]
11511175

1152-
subtitle_pos_x = []
1153-
for index in range(len(x_dom)):
1154-
subtitle_pos_x.append(((x_dom[index][1])-(x_dom[index][0]))/2 +
1155-
x_dom[index][0])
1176+
subtitle_pos_x = []
1177+
for index in range(len(x_dom)):
1178+
subtitle_pos_x.append(((x_dom[index][1])-(x_dom[index][0]))/2 +
1179+
x_dom[index][0])
11561180

1157-
subtitle_pos_y = []
1158-
for index in range(len(y_dom)):
1159-
subtitle_pos_y.append(y_dom[index][1])
1181+
subtitle_pos_y = []
1182+
for index in range(len(y_dom)):
1183+
subtitle_pos_y.append(y_dom[index][1])
11601184

1161-
plot_titles = []
1162-
for index in range(len(x_dom)):
1185+
plot_titles = []
1186+
for index in range(len(subplot_titles)):
1187+
if not subplot_titles[index]:
1188+
pass
1189+
else:
11631190
plot_titles.append({'y': subtitle_pos_y[index],
11641191
'xref': 'paper',
11651192
'x': subtitle_pos_x[index],

0 commit comments

Comments
 (0)