Skip to content

Commit 4c45ee9

Browse files
committed
make_subplot titles edits
- Fix font size - Change vertical spacing when subplot are titles to try and avoid overlap w/ x-axis labels - Fix tests to reflect the new default spacing
1 parent 4849c7e commit 4c45ee9

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

plotly/tests/test_core/test_tools/test_make_subplots.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,18 +1941,18 @@ def test_subplot_titles_2x1():
19411941
yref='paper',
19421942
text='Title 1',
19431943
showarrow=False,
1944-
font=Font(size=18),
1944+
font=Font(size=16),
19451945
xanchor='center',
19461946
yanchor='bottom'
19471947
),
19481948
Annotation(
19491949
x=0.5,
1950-
y=0.425,
1950+
y=0.375,
19511951
xref='paper',
19521952
yref='paper',
19531953
text='Title 2',
19541954
showarrow=False,
1955-
font=Font(size=18),
1955+
font=Font(size=16),
19561956
xanchor='center',
19571957
yanchor='bottom'
19581958
)
@@ -1966,11 +1966,11 @@ def test_subplot_titles_2x1():
19661966
anchor='y2'
19671967
),
19681968
yaxis1=YAxis(
1969-
___domain=[0.575, 1.0],
1969+
___domain=[0.625, 1.0],
19701970
anchor='x1'
19711971
),
19721972
yaxis2=YAxis(
1973-
___domain=[0.0, 0.425],
1973+
___domain=[0.0, 0.375],
19741974
anchor='x2'
19751975
)
19761976
)
@@ -1992,7 +1992,7 @@ def test_subplot_titles_1x3():
19921992
yref='paper',
19931993
text='Title 1',
19941994
showarrow=False,
1995-
font=Font(size=18),
1995+
font=Font(size=16),
19961996
xanchor='center',
19971997
yanchor='bottom'
19981998
),
@@ -2003,7 +2003,7 @@ def test_subplot_titles_1x3():
20032003
yref='paper',
20042004
text='Title 2',
20052005
showarrow=False,
2006-
font=Font(size=18),
2006+
font=Font(size=16),
20072007
xanchor='center',
20082008
yanchor='bottom'
20092009
),
@@ -2014,7 +2014,7 @@ def test_subplot_titles_1x3():
20142014
yref='paper',
20152015
text='Title 3',
20162016
showarrow=False,
2017-
font=Font(size=18),
2017+
font=Font(size=16),
20182018
xanchor='center',
20192019
yanchor='bottom'
20202020
)
@@ -2063,7 +2063,7 @@ def test_subplot_titles_shared_axes():
20632063
yref='paper',
20642064
text='Title 1',
20652065
showarrow=False,
2066-
font=Font(size=18),
2066+
font=Font(size=16),
20672067
xanchor='center',
20682068
yanchor='bottom'
20692069
),
@@ -2074,29 +2074,29 @@ def test_subplot_titles_shared_axes():
20742074
yref='paper',
20752075
text='Title 2',
20762076
showarrow=False,
2077-
font=Font(size=18),
2077+
font=Font(size=16),
20782078
xanchor='center',
20792079
yanchor='bottom'
20802080
),
20812081
Annotation(
20822082
x=0.22499999999999998,
2083-
y=0.42500000000000004,
2083+
y=0.375,
20842084
xref='paper',
20852085
yref='paper',
20862086
text='Title 3',
20872087
showarrow=False,
2088-
font=Font(size=18),
2088+
font=Font(size=16),
20892089
xanchor='center',
20902090
yanchor='bottom'
20912091
),
20922092
Annotation(
20932093
x=0.7749999999999999,
2094-
y=0.42500000000000004,
2094+
y=0.375,
20952095
xref='paper',
20962096
yref='paper',
20972097
text='Title 4',
20982098
showarrow=False,
2099-
font=Font(size=18),
2099+
font=Font(size=16),
21002100
xanchor='center',
21012101
yanchor='bottom'
21022102
)
@@ -2111,12 +2111,12 @@ def test_subplot_titles_shared_axes():
21112111
position=0.0
21122112
),
21132113
yaxis1=YAxis(
2114-
___domain=[0.575, 1.0],
2114+
___domain=[0.625, 1.0],
21152115
anchor='free',
21162116
position=0.0
21172117
),
21182118
yaxis2=YAxis(
2119-
___domain=[0.0, 0.425],
2119+
___domain=[0.0, 0.375],
21202120
anchor='x1'
21212121
)
21222122
)
@@ -2142,7 +2142,7 @@ def test_subplot_titles_irregular_layout():
21422142
yref='paper',
21432143
text='Title 1',
21442144
showarrow=False,
2145-
font=Font(size=18),
2145+
font=Font(size=16),
21462146
xanchor='center',
21472147
yanchor='bottom'
21482148
),
@@ -2153,18 +2153,18 @@ def test_subplot_titles_irregular_layout():
21532153
yref='paper',
21542154
text='Title 2',
21552155
showarrow=False,
2156-
font=Font(size=18),
2156+
font=Font(size=16),
21572157
xanchor='center',
21582158
yanchor='bottom'
21592159
),
21602160
Annotation(
21612161
x=0.5,
2162-
y=0.425,
2162+
y=0.375,
21632163
xref='paper',
21642164
yref='paper',
21652165
text='Title 3',
21662166
showarrow=False,
2167-
font=Font(size=18),
2167+
font=Font(size=16),
21682168
xanchor='center',
21692169
yanchor='bottom'
21702170
)
@@ -2182,15 +2182,15 @@ def test_subplot_titles_irregular_layout():
21822182
anchor='y3'
21832183
),
21842184
yaxis1=YAxis(
2185-
___domain=[0.575, 1.0],
2185+
___domain=[0.625, 1.0],
21862186
anchor='x1'
21872187
),
21882188
yaxis2=YAxis(
2189-
___domain=[0.575, 1.0],
2189+
___domain=[0.625, 1.0],
21902190
anchor='x2'
21912191
),
21922192
yaxis3=YAxis(
2193-
___domain=[0.0, 0.425],
2193+
___domain=[0.0, 0.375],
21942194
anchor='x3'
21952195
)
21962196
)
@@ -2215,7 +2215,7 @@ def test_subplot_titles_insets():
22152215
yref='paper',
22162216
text='Inset',
22172217
showarrow=False,
2218-
font=Font(size=18),
2218+
font=Font(size=16),
22192219
xanchor='center',
22202220
yanchor='bottom'
22212221
)

plotly/tools.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,9 @@ def make_subplots(rows=1, cols=1,
754754
if key not in VALID_KWARGS:
755755
raise Exception("Invalid keyword argument: '{0}'".format(key))
756756

757+
# Set 'subplot_titles'
758+
subplot_titles = kwargs.get('subplot_titles', [""] * rows * cols)
759+
757760
# Set 'horizontal_spacing' / 'vertical_spacing' w.r.t. rows / cols
758761
try:
759762
horizontal_spacing = float(kwargs['horizontal_spacing'])
@@ -762,10 +765,10 @@ def make_subplots(rows=1, cols=1,
762765
try:
763766
vertical_spacing = float(kwargs['vertical_spacing'])
764767
except KeyError:
765-
vertical_spacing = 0.3 / rows
766-
767-
# Set 'subplot_titles'
768-
subplot_titles = kwargs.get('subplot_titles', [""] * rows * cols)
768+
if 'subplot_titles' in kwargs:
769+
vertical_spacing = 0.5 / rows
770+
else:
771+
vertical_spacing = 0.3 / rows
769772

770773
# Sanitize 'specs' (must be a list of lists)
771774
exception_msg = "Keyword argument 'specs' must be a list of lists"
@@ -1205,7 +1208,7 @@ def _pad(s, cell_len=cell_len):
12051208
'yref': 'paper',
12061209
'text': subplot_titles[index],
12071210
'showarrow': False,
1208-
'font': graph_objs.Font(size=18),
1211+
'font': graph_objs.Font(size=16),
12091212
'xanchor': 'center',
12101213
'yanchor': 'bottom'
12111214
})

0 commit comments

Comments
 (0)