Skip to content

Commit dd16fa2

Browse files
committed
define START_CELL and build grid using it
1 parent a311719 commit dd16fa2

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

plotly/tools.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,27 @@ def make_subplots(rows=1, cols=1,
653653
if not isinstance(cols, int):
654654
raise Exception("Keyword argument 'cols' must be an int")
655655

656+
# Dictionary of things start_cell
657+
START_CELL_all = {
658+
'bottom-left': {
659+
# 'natural' setup where x & y domains increase monotonically
660+
'col_dir': 1,
661+
'row_dir': 1
662+
},
663+
'top-left': {
664+
# 'default' setup visually matching the 'specs' list of lists
665+
'col_dir': 1,
666+
'row_dir': -1
667+
}
668+
# TODO maybe add 'bottom-right' and 'top-right'
669+
}
670+
671+
# Throw exception for invalid 'start_cell' values
672+
try:
673+
START_CELL = START_CELL_all[start_cell]
674+
except KeyError:
675+
raise Exception("Invalid 'start_cell' value")
676+
656677
# Throw exception if non-valid kwarg is sent
657678
VALID_KWARGS = ['horizontal_spacing', 'vertical_spacing',
658679
'specs', 'insets']
@@ -752,12 +773,17 @@ def _checks(item, defaults):
752773
width = (1. - horizontal_spacing * (cols - 1)) / cols
753774
height = (1. - vertical_spacing * (rows - 1)) / rows
754775

755-
# Build subplot grid (tuple of starting coords for each cell)
756-
grid = [[((width + horizontal_spacing) * column,
757-
(height + vertical_spacing) * row)
758-
for column in range(columns)]
759-
for row in range(rows)] # all we need
760-
776+
# Built row/col sequence using 'row_dir' and 'col_dir'
777+
col_dir = START_CELL['col_dir']
778+
col_seq = range(cols)[::col_dir]
779+
row_dir = START_CELL['row_dir']
780+
row_seq = range(rows)[::row_dir]
781+
782+
# [grid] Build subplot grid (coord tuple of cell)
783+
grid = [[((width + horizontal_spacing) * c,
784+
(height + vertical_spacing) * r)
785+
for c in col_seq]
786+
for r in row_seq]
761787
# Initialize the grid's string representation
762788
if print_grid:
763789
grid_str = [['' for column in range(columns)] for row in range(rows)]

0 commit comments

Comments
 (0)