@@ -882,59 +882,71 @@ def _add_domain_is_3d(fig, s_cnt, x_domain, y_domain):
882
882
883
883
x_cnt = y_cnt = s_cnt = 1 # subplot axis/scene counters
884
884
885
- # Loop through specs
886
- for row , spec_row in enumerate (specs ):
885
+ # Loop through specs -- (r, c) <-> (row, col)
886
+ for r , spec_row in enumerate (specs ):
887
+ for c , spec in enumerate (spec_row ):
887
888
889
+ if spec is None : # skip over None cells
890
+ continue
888
891
889
- for col , spec in enumerate (spec_row ):
892
+ c_spanned = c + spec ['colspan' ] - 1 # get spanned c
893
+ r_spanned = r + spec ['rowspan' ] - 1 # get spanned r
890
894
891
- # String representation for empty cells
892
- if spec is None :
893
- if print_grid and grid_str [i ][j ] == '' :
894
- grid_str [i ][j ] = '{none}'
895
- j += 1
896
- continue
895
+ # Throw exception if 'colspan' | 'rowspan' is too large for grid
896
+ if c_spanned >= cols :
897
+ raise Exception ("Some 'colspan' value is too large for "
898
+ "this subplot grid." )
899
+ if r_spanned >= rows :
900
+ raise Exception ("Some 'rowspan' value is too large for "
901
+ "this subplot grid." )
897
902
898
903
# Get x domain using grid and colspan
899
- x_s = grid [i ][ j ][0 ] + spec ['l' ]
900
- x_e = grid [i ][ j + ( spec [ 'colspan' ] - 1 ) ][0 ] + width - spec ['r' ]
904
+ x_s = grid [r ][ c ][0 ] + spec ['l' ]
905
+ x_e = grid [r ][ c_spanned ][0 ] + width - spec ['r' ]
901
906
x_domain = [x_s , x_e ]
902
907
903
- # Get y domain using grid and rowspan
904
- y_s = grid [i ][j ][1 ] + spec ['b' ]
905
- y_e = grid [i + (spec ['rowspan' ]- 1 )][j ][1 ] + height - spec ['t' ]
908
+ # Get y domain (dep. on row_dir) using grid & r_spanned
909
+ if row_dir > 0 :
910
+ y_s = grid [r ][c ][1 ] + spec ['b' ]
911
+ y_e = grid [r_spanned ][c ][1 ] + height - spec ['t' ]
912
+ else :
913
+ y_s = grid [r_spanned ][c ][1 ] + spec ['b' ]
914
+ y_e = grid [r ][c ][1 ] + height - spec ['t' ]
906
915
y_domain = [y_s , y_e ]
907
916
908
917
if spec ['is_3d' ]:
918
+
909
919
# Add scene to layout
910
- _add_domain_is_3d ( fig , s_cnt , x_domain , y_domain )
911
- if print_grid :
912
- grid_str [ i ][ j ] = '[scene{}' . format ( s_cnt )
920
+ s_label = 'scene{0}' . format ( s_cnt )
921
+ _add_domain_is_3d ( layout , s_label , x_domain , y_domain )
922
+ grid_ref [ r ][ c ] = ( s_label , )
913
923
s_cnt += 1
924
+
914
925
else :
915
926
916
927
# Get axis label and anchor
917
- x_label = _get_label ('x' , row , col , x_cnt , shared_xaxes )
918
- y_label = _get_label ('y' , row , col , y_cnt , shared_yaxes )
919
- x_anchor , y_anchor = _get_anchors (row , col ,
928
+ x_label = _get_label ('x' , r , c , x_cnt , shared_xaxes )
929
+ y_label = _get_label ('y' , r , c , y_cnt , shared_yaxes )
930
+ x_anchor , y_anchor = _get_anchors (r , c ,
920
931
x_cnt , y_cnt ,
921
932
shared_xaxes ,
922
933
shared_yaxes )
923
934
924
935
# Add a xaxis to layout (N.B anchor == False -> no axis)
925
936
if x_anchor :
926
937
x_position = y_domain [0 ] if x_anchor == 'free' else 0
927
- _add_domain (fig , 'x' , x_label , x_domain ,
938
+ _add_domain (layout , 'x' , x_label , x_domain ,
928
939
x_anchor , x_position )
929
940
x_cnt += 1
930
941
931
942
# Add a yaxis to layout (N.B anchor == False -> no axis)
932
943
if y_anchor :
933
944
y_position = x_domain [0 ] if y_anchor == 'free' else 0
934
- _add_domain (fig , 'y' , y_label , y_domain ,
945
+ _add_domain (layout , 'y' , y_label , y_domain ,
935
946
y_anchor , y_position )
936
947
y_cnt += 1
937
948
949
+ grid_ref [r ][c ] = (x_label , y_label ) # fill in ref
938
950
if print_grid :
939
951
grid_str [i ][j ] = '[{},{}' .format (x_label , y_label )
940
952
0 commit comments