@@ -772,6 +772,32 @@ def make_subplots(rows=1, cols=1,
772
772
in fraction of cell height
773
773
* h (float or 'to_end', default='to_end') inset height
774
774
in fraction of cell height ('to_end': to cell top edge)
775
+
776
+ column_width (kwarg, list of numbers)
777
+ Column_width specifications
778
+
779
+ - Functions similarly to `column_width` of `plotly.graph_objs.Table`.
780
+ Specify a list that contains numbers where the amount of numbers in
781
+ the list is equal to `cols`.
782
+
783
+ - The numbers in the list indicate the proportions that each column
784
+ domains take across the full horizontal domain excluding padding.
785
+
786
+ - For example, if columns_width=[3, 1], horizontal_spacing=0, and
787
+ cols=2, the domains for each column would be [0. 0.75] and [0.75, 1]
788
+
789
+ row_width (kwargs, list of numbers)
790
+ Row_width specifications
791
+
792
+ - Functions similarly to `column_width`. Specify a list that contains
793
+ numbers where the amount of numbers in the list is equal to `rows`.
794
+
795
+ - The numbers in the list indicate the proportions that each row
796
+ domains take along the full vertical domain excluding padding.
797
+
798
+ - For example, if row_width=[3, 1], vertical_spacing=0, and
799
+ cols=2, the domains for each row from top to botton would be
800
+ [0. 0.75] and [0.75, 1]
775
801
"""
776
802
# TODO: protected until #282
777
803
from plotly .graph_objs import graph_objs
@@ -807,7 +833,8 @@ def make_subplots(rows=1, cols=1,
807
833
808
834
# Throw exception if non-valid kwarg is sent
809
835
VALID_KWARGS = ['horizontal_spacing' , 'vertical_spacing' ,
810
- 'specs' , 'insets' , 'subplot_titles' ]
836
+ 'specs' , 'insets' , 'subplot_titles' , 'column_width' ,
837
+ 'row_width' ]
811
838
for key in kwargs .keys ():
812
839
if key not in VALID_KWARGS :
813
840
raise Exception ("Invalid keyword argument: '{0}'" .format (key ))
@@ -907,9 +934,47 @@ def _checks(item, defaults):
907
934
)
908
935
_check_keys_and_fill ('insets' , insets , INSET_defaults )
909
936
910
- # Set width & height of each subplot cell (excluding padding)
911
- width = (1. - horizontal_spacing * (cols - 1 )) / cols
912
- height = (1. - vertical_spacing * (rows - 1 )) / rows
937
+ # set heights (with 'column_width')
938
+ try :
939
+ column_width = kwargs ['column_width' ]
940
+ if not isinstance (column_width , list ) or len (column_width ) != cols :
941
+ raise Exception (
942
+ "Keyword argument 'column_width' must be a list with {} "
943
+ "numbers in it, the number of subplot cols." .format (cols )
944
+ )
945
+ except KeyError :
946
+ column_width = None
947
+
948
+ if column_width :
949
+ cum_sum = float (sum (column_width ))
950
+ widths = []
951
+ for w in column_width :
952
+ widths .append (
953
+ (1. - horizontal_spacing * (cols - 1 )) * (w / cum_sum )
954
+ )
955
+ else :
956
+ widths = [(1. - horizontal_spacing * (cols - 1 )) / cols ] * cols
957
+
958
+ # set widths (with 'row_width')
959
+ try :
960
+ row_width = kwargs ['row_width' ]
961
+ if not isinstance (row_width , list ) or len (row_width ) != rows :
962
+ raise Exception (
963
+ "Keyword argument 'row_width' must be a list with {} "
964
+ "numbers in it, the number of subplot rows." .format (rows )
965
+ )
966
+ except KeyError :
967
+ row_width = None
968
+
969
+ if row_width :
970
+ cum_sum = float (sum (row_width ))
971
+ heights = []
972
+ for h in row_width :
973
+ heights .append (
974
+ (1. - vertical_spacing * (rows - 1 )) * (h / cum_sum )
975
+ )
976
+ else :
977
+ heights = [(1. - vertical_spacing * (rows - 1 )) / rows ] * rows
913
978
914
979
# Built row/col sequence using 'row_dir' and 'col_dir'
915
980
COL_DIR = START_CELL ['col_dir' ]
@@ -918,10 +983,14 @@ def _checks(item, defaults):
918
983
row_seq = range (rows )[::ROW_DIR ]
919
984
920
985
# [grid] Build subplot grid (coord tuple of cell)
921
- grid = [[((width + horizontal_spacing ) * c ,
922
- (height + vertical_spacing ) * r )
923
- for c in col_seq ]
924
- for r in row_seq ]
986
+ grid = [
987
+ [
988
+ (
989
+ (sum (widths [:c ]) + c * horizontal_spacing ),
990
+ (sum (heights [:r ]) + r * vertical_spacing )
991
+ ) for c in col_seq
992
+ ] for r in row_seq
993
+ ]
925
994
926
995
# [grid_ref] Initialize the grid and insets' axis-reference lists
927
996
grid_ref = [[None for c in range (cols )] for r in range (rows )]
@@ -1040,16 +1109,16 @@ def _add_domain_is_3d(layout, s_label, x_domain, y_domain):
1040
1109
1041
1110
# Get x domain using grid and colspan
1042
1111
x_s = grid [r ][c ][0 ] + spec ['l' ]
1043
- x_e = grid [r ][c_spanned ][0 ] + width - spec ['r' ]
1112
+ x_e = grid [r ][c_spanned ][0 ] + widths [ c ] - spec ['r' ]
1044
1113
x_domain = [x_s , x_e ]
1045
1114
1046
1115
# Get y domain (dep. on row_dir) using grid & r_spanned
1047
1116
if ROW_DIR > 0 :
1048
1117
y_s = grid [r ][c ][1 ] + spec ['b' ]
1049
- y_e = grid [r_spanned ][c ][1 ] + height - spec ['t' ]
1118
+ y_e = grid [r_spanned ][c ][1 ] + heights [ - 1 - r ] - spec ['t' ]
1050
1119
else :
1051
1120
y_s = grid [r_spanned ][c ][1 ] + spec ['b' ]
1052
- y_e = grid [r ][c ][1 ] + height - spec ['t' ]
1121
+ y_e = grid [r ][c ][1 ] + heights [ - 1 - r ] - spec ['t' ]
1053
1122
y_domain = [y_s , y_e ]
1054
1123
1055
1124
if spec ['is_3d' ]:
@@ -1108,19 +1177,19 @@ def _add_domain_is_3d(layout, s_label, x_domain, y_domain):
1108
1177
"Note: the starting cell is (1, 1)" )
1109
1178
1110
1179
# Get inset x domain using grid
1111
- x_s = grid [r ][c ][0 ] + inset ['l' ] * width
1180
+ x_s = grid [r ][c ][0 ] + inset ['l' ] * widths [ c ]
1112
1181
if inset ['w' ] == 'to_end' :
1113
- x_e = grid [r ][c ][0 ] + width
1182
+ x_e = grid [r ][c ][0 ] + widths [ c ]
1114
1183
else :
1115
- x_e = x_s + inset ['w' ] * width
1184
+ x_e = x_s + inset ['w' ] * widths [ c ]
1116
1185
x_domain = [x_s , x_e ]
1117
1186
1118
1187
# Get inset y domain using grid
1119
- y_s = grid [r ][c ][1 ] + inset ['b' ] * height
1188
+ y_s = grid [r ][c ][1 ] + inset ['b' ] * heights [ - 1 - r ]
1120
1189
if inset ['h' ] == 'to_end' :
1121
- y_e = grid [r ][c ][1 ] + height
1190
+ y_e = grid [r ][c ][1 ] + heights [ - 1 - r ]
1122
1191
else :
1123
- y_e = y_s + inset ['h' ] * height
1192
+ y_e = y_s + inset ['h' ] * heights [ - 1 - r ]
1124
1193
y_domain = [y_s , y_e ]
1125
1194
1126
1195
if inset ['is_3d' ]:
0 commit comments