@@ -1136,11 +1136,19 @@ def infer_config(args, constructor, trace_patch):
11361136def get_orderings (args , grouper , grouped ):
11371137 """
11381138 `orders` is the user-supplied ordering (with the remaining data-frame-supplied
1139- ordering appended if the column is used for grouping)
1139+ ordering appended if the column is used for grouping). It includes anything the user
1140+ gave, for any variable, including values not present in the dataset. It is used
1141+ downstream to set e.g. `categoryarray` for cartesian axes
1142+
11401143 `group_names` is the set of groups, ordered by the order above
1144+
1145+ `group_values` is a subset of `orders` in both keys and values. It contains a key
1146+ for every grouped mapping and its values are the sorted *data* values for these
1147+ mappings.
11411148 """
11421149 orders = {} if "category_orders" not in args else args ["category_orders" ].copy ()
11431150 group_names = []
1151+ group_values = {}
11441152 for group_name in grouped .groups :
11451153 if len (grouper ) == 1 :
11461154 group_name = (group_name ,)
@@ -1154,6 +1162,7 @@ def get_orderings(args, grouper, grouped):
11541162 for val in uniques :
11551163 if val not in orders [col ]:
11561164 orders [col ].append (val )
1165+ group_values [col ] = sorted (uniques , key = orders [col ].index )
11571166
11581167 for i , col in reversed (list (enumerate (grouper ))):
11591168 if col != one_group :
@@ -1162,7 +1171,7 @@ def get_orderings(args, grouper, grouped):
11621171 key = lambda g : orders [col ].index (g [i ]) if g [i ] in orders [col ] else - 1 ,
11631172 )
11641173
1165- return orders , group_names
1174+ return orders , group_names , group_values
11661175
11671176
11681177def make_figure (args , constructor , trace_patch = {}, layout_patch = {}):
@@ -1174,16 +1183,31 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}):
11741183 grouper = [x .grouper or one_group for x in grouped_mappings ] or [one_group ]
11751184 grouped = args ["data_frame" ].groupby (grouper , sort = False )
11761185
1177- orders , sorted_group_names = get_orderings (args , grouper , grouped )
1186+ orders , sorted_group_names , sorted_group_values = get_orderings (
1187+ args , grouper , grouped
1188+ )
1189+
1190+ col_labels = []
1191+ row_labels = []
1192+
1193+ for m in grouped_mappings :
1194+ if m .grouper :
1195+ if m .facet == "col" :
1196+ prefix = get_label (args , args ["facet_col" ]) + "="
1197+ col_labels = [prefix + str (s ) for s in sorted_group_values [m .grouper ]]
1198+ if m .facet == "row" :
1199+ prefix = get_label (args , args ["facet_row" ]) + "="
1200+ row_labels = [prefix + str (s ) for s in sorted_group_values [m .grouper ]]
1201+ for val in sorted_group_values [m .grouper ]:
1202+ if val not in m .val_map :
1203+ m .val_map [val ] = m .sequence [len (m .val_map ) % len (m .sequence )]
11781204
11791205 subplot_type = _subplot_type_for_trace_type (constructor ().type )
11801206
11811207 trace_names_by_frame = {}
11821208 frames = OrderedDict ()
11831209 trendline_rows = []
11841210 nrows = ncols = 1
1185- col_labels = []
1186- row_labels = []
11871211 trace_name_labels = None
11881212 for group_name in sorted_group_names :
11891213 group = grouped .get_group (group_name if len (group_name ) > 1 else group_name [0 ])
@@ -1281,10 +1305,6 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}):
12811305 # Find row for trace, handling facet_row and marginal_x
12821306 if m .facet == "row" :
12831307 row = m .val_map [val ]
1284- if args ["facet_row" ] and len (row_labels ) < row :
1285- row_labels .append (
1286- get_label (args , args ["facet_row" ]) + "=" + str (val )
1287- )
12881308 else :
12891309 if (
12901310 bool (args .get ("marginal_x" , False ))
@@ -1298,10 +1318,6 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}):
12981318 # Find col for trace, handling facet_col and marginal_y
12991319 if m .facet == "col" :
13001320 col = m .val_map [val ]
1301- if args ["facet_col" ] and len (col_labels ) < col :
1302- col_labels .append (
1303- get_label (args , args ["facet_col" ]) + "=" + str (val )
1304- )
13051321 if facet_col_wrap : # assumes no facet_row, no marginals
13061322 row = 1 + ((col - 1 ) // facet_col_wrap )
13071323 col = 1 + ((col - 1 ) % facet_col_wrap )
0 commit comments