Skip to content

Commit 8dfcfe2

Browse files
committed
update subplot test to reflect change in number of binary operations in subplot width calcs
1 parent 114cf50 commit 8dfcfe2

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

plotly/tests/test_core/test_tools/test_make_subplots.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def test_a_lot(self):
193193
anchor='y12'
194194
),
195195
xaxis13=XAxis(
196-
___domain=[0.7346938775510203, 0.8530612244897958],
196+
___domain=[0.7346938775510204, 0.8530612244897959],
197197
anchor='y13'
198198
),
199199
xaxis14=XAxis(
@@ -225,7 +225,7 @@ def test_a_lot(self):
225225
anchor='y2'
226226
),
227227
xaxis20=XAxis(
228-
___domain=[0.7346938775510203, 0.8530612244897958],
228+
___domain=[0.7346938775510204, 0.8530612244897959],
229229
anchor='y20'
230230
),
231231
xaxis21=XAxis(
@@ -253,7 +253,7 @@ def test_a_lot(self):
253253
anchor='y26'
254254
),
255255
xaxis27=XAxis(
256-
___domain=[0.7346938775510203, 0.8530612244897958],
256+
___domain=[0.7346938775510204, 0.8530612244897959],
257257
anchor='y27'
258258
),
259259
xaxis28=XAxis(
@@ -273,7 +273,7 @@ def test_a_lot(self):
273273
anchor='y5'
274274
),
275275
xaxis6=XAxis(
276-
___domain=[0.7346938775510203, 0.8530612244897958],
276+
___domain=[0.7346938775510204, 0.8530612244897959],
277277
anchor='y6'
278278
),
279279
xaxis7=XAxis(
@@ -426,7 +426,7 @@ def test_a_lot_bottom_left(self):
426426
anchor='y12'
427427
),
428428
xaxis13=XAxis(
429-
___domain=[0.7346938775510203, 0.8530612244897958],
429+
___domain=[0.7346938775510204, 0.8530612244897959],
430430
anchor='y13'
431431
),
432432
xaxis14=XAxis(
@@ -458,7 +458,7 @@ def test_a_lot_bottom_left(self):
458458
anchor='y2'
459459
),
460460
xaxis20=XAxis(
461-
___domain=[0.7346938775510203, 0.8530612244897958],
461+
___domain=[0.7346938775510204, 0.8530612244897959],
462462
anchor='y20'
463463
),
464464
xaxis21=XAxis(
@@ -486,7 +486,7 @@ def test_a_lot_bottom_left(self):
486486
anchor='y26'
487487
),
488488
xaxis27=XAxis(
489-
___domain=[0.7346938775510203, 0.8530612244897958],
489+
___domain=[0.7346938775510204, 0.8530612244897959],
490490
anchor='y27'
491491
),
492492
xaxis28=XAxis(
@@ -506,7 +506,7 @@ def test_a_lot_bottom_left(self):
506506
anchor='y5'
507507
),
508508
xaxis6=XAxis(
509-
___domain=[0.7346938775510203, 0.8530612244897958],
509+
___domain=[0.7346938775510204, 0.8530612244897959],
510510
anchor='y6'
511511
),
512512
xaxis7=XAxis(

plotly/tools.py

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,7 @@ def make_subplots(rows=1, cols=1,
807807

808808
# Throw exception if non-valid kwarg is sent
809809
VALID_KWARGS = ['horizontal_spacing', 'vertical_spacing',
810-
'specs', 'insets', 'subplot_titles', 'column_width',
811-
'row_width']
810+
'specs', 'insets', 'subplot_titles', 'column_width']
812811
for key in kwargs.keys():
813812
if key not in VALID_KWARGS:
814813
raise Exception("Invalid keyword argument: '{0}'".format(key))
@@ -908,24 +907,44 @@ def _checks(item, defaults):
908907
)
909908
_check_keys_and_fill('insets', insets, INSET_defaults)
910909

911-
# Set width & height of each subplot cell (excluding padding)
912-
width = (1. - horizontal_spacing * (cols - 1)) / cols
910+
# Set height of each subplot cell (excluding padding)
913911
height = (1. - vertical_spacing * (rows - 1)) / rows
914912

913+
try:
914+
column_width = kwargs['column_width']
915+
if not isinstance(column_width, list) or len(column_width) != cols:
916+
raise Exception(
917+
"Keyword argument 'column_width' must be a list "
918+
"containing the same number of floats as the number of cols."
919+
)
920+
except KeyError:
921+
column_width = None
922+
923+
if column_width:
924+
cum_sum = float(sum(column_width))
925+
widths = []
926+
for w in column_width:
927+
widths.append(
928+
(1. - horizontal_spacing * (cols - 1)) * (w / cum_sum)
929+
)
930+
else:
931+
widths = [(1. - horizontal_spacing * (cols - 1)) / cols] * cols
932+
915933
# Built row/col sequence using 'row_dir' and 'col_dir'
916934
COL_DIR = START_CELL['col_dir']
917935
ROW_DIR = START_CELL['row_dir']
918936
col_seq = range(cols)[::COL_DIR]
919937
row_seq = range(rows)[::ROW_DIR]
920938

921939
# [grid] Build subplot grid (coord tuple of cell)
922-
grid = [[((width + horizontal_spacing) * c,
923-
(height + vertical_spacing) * r)
924-
for c in col_seq]
925-
for r in row_seq]
926-
927-
import pprint
928-
pprint.pprint(grid)
940+
grid = [
941+
[
942+
(
943+
(sum(widths[:c]) + c * horizontal_spacing),
944+
(height + vertical_spacing) * r
945+
) for c in col_seq
946+
] for r in row_seq
947+
]
929948

930949
# [grid_ref] Initialize the grid and insets' axis-reference lists
931950
grid_ref = [[None for c in range(cols)] for r in range(rows)]
@@ -1042,15 +1061,9 @@ def _add_domain_is_3d(layout, s_label, x_domain, y_domain):
10421061
raise Exception("Some 'rowspan' value is too large for "
10431062
"this subplot grid.")
10441063

1045-
print grid[r][c]
1046-
print grid[r][c_spanned]
1047-
print "width is {}".format(width)
1048-
print "height is {}".format(height)
1049-
print '\n\n'
1050-
10511064
# Get x ___domain using grid and colspan
10521065
x_s = grid[r][c][0] + spec['l']
1053-
x_e = grid[r][c_spanned][0] + width - spec['r']
1066+
x_e = grid[r][c_spanned][0] + widths[c] - spec['r']
10541067
x_domain = [x_s, x_e]
10551068

10561069
# Get y ___domain (dep. on row_dir) using grid & r_spanned
@@ -1118,11 +1131,11 @@ def _add_domain_is_3d(layout, s_label, x_domain, y_domain):
11181131
"Note: the starting cell is (1, 1)")
11191132

11201133
# Get inset x ___domain using grid
1121-
x_s = grid[r][c][0] + inset['l'] * width
1134+
x_s = grid[r][c][0] + inset['l'] * widths[c]
11221135
if inset['w'] == 'to_end':
1123-
x_e = grid[r][c][0] + width
1136+
x_e = grid[r][c][0] + widths[c]
11241137
else:
1125-
x_e = x_s + inset['w'] * width
1138+
x_e = x_s + inset['w'] * widths[c]
11261139
x_domain = [x_s, x_e]
11271140

11281141
# Get inset y ___domain using grid

0 commit comments

Comments
 (0)