@@ -121,6 +121,9 @@ def __init__(self,
121
121
self .color_coloumn_placeholder = "value_color_col_placeholder_VCCP"
122
122
self .same_var_placeholder = "_same_var_placeholder_SVP_"
123
123
124
+ # to resolve same_scale and value_order alignment issue
125
+ self .same_scale_placeholder = "_same_scale_placeholder_SSP_"
126
+
124
127
def plot (self ,
125
128
var : List [str ] = None ,
126
129
value_order : Dict [str , Dict [int , str ]] = None ,
@@ -136,7 +139,7 @@ def plot(self,
136
139
default_color = "lightskyblue" ,
137
140
# Manipulating Spacing and Layout
138
141
bar_width : float = 1. ,
139
- min_bar_width : float = .05 ,
142
+ min_bar_width : float = .1 ,
140
143
space : float = .5 ,
141
144
label_options : Dict = None ,
142
145
height : float = 10. ,
@@ -249,11 +252,6 @@ def plot(self,
249
252
self .shape = shape
250
253
self .same_scale = same_scale
251
254
252
- if self .label and self .space == 0 :
253
- raise ValueError (
254
- f'space must not be 0 if label = True.'
255
- )
256
-
257
255
if self .missing :
258
256
self .data_df = self .data_df .fillna (self .missing_data_placeholder )
259
257
else :
@@ -284,7 +282,7 @@ def plot(self,
284
282
data_point_numbers = []
285
283
for p in var_pairs :
286
284
varname_p = [self ._get_varname (var ) for var in p ]
287
- pair_dict_temp = self .data_df .groupby (varname_p ).size ().to_dict ()
285
+ pair_dict_temp = self .data_df .groupby (varname_p , observed = True ).size ().to_dict ()
288
286
pair_dict = {}
289
287
for k , v in pair_dict_temp .items ():
290
288
if v == 0 :
@@ -298,7 +296,7 @@ def plot(self,
298
296
for p in var_pairs :
299
297
varname_p = [self ._get_varname (var ) for var in p ]
300
298
varname_p .append (self .color_coloumn_placeholder )
301
- color_dict_temp = self .data_df .groupby (varname_p ).size ().to_dict ()
299
+ color_dict_temp = self .data_df .groupby (varname_p , observed = True ).size ().to_dict ()
302
300
color_dict = {}
303
301
for k , v in color_dict_temp .items ():
304
302
if v == 0 :
@@ -428,23 +426,22 @@ def plot(self,
428
426
if k [1 ] == the_hi_value and self .hi_var == col_name :
429
427
label_rectangle_width_temp = label_rectangle_widths [idx ]
430
428
label_rectangle_total_obvs_color [k ] = 0
431
- # case2: for other colors
432
- elif the_hi_value :
433
- num_obv = self .data_df .groupby ([self .hi_var , col_name ]).size ().get ((the_hi_value , k [1 ]), 0 )
429
+ # case2: for other variables
430
+ elif the_hi_value != None :
431
+ num_obv = self .data_df .groupby ([self .hi_var , col_name ], observed = True ).size ().get ((the_hi_value , k [1 ]), 0 )
434
432
label_rectangle_width_temp = bar * num_obv
435
- if self .min_bar_width and label_rectangle_width_temp <= self .min_bar_width and label_rectangle_width_temp != 0 :
436
- label_rectangle_width_temp = self .min_bar_width
433
+ # if self.min_bar_width and label_rectangle_width_temp <= self.min_bar_width and label_rectangle_width_temp != 0:
434
+ # label_rectangle_width_temp = self.min_bar_width
437
435
label_rectangle_total_obvs_color [k ] -= num_obv
438
436
# case3: for the last default color
439
437
else :
440
438
label_rectangle_width_temp = bar * label_rectangle_total_obvs_color [k ]
441
- if self .min_bar_width and label_rectangle_width_temp <= self .min_bar_width and label_rectangle_width_temp != 0 :
442
- label_rectangle_width_temp = self .min_bar_width
439
+ # if self.min_bar_width and label_rectangle_width_temp <= self.min_bar_width and label_rectangle_width_temp != 0:
440
+ # label_rectangle_width_temp = self.min_bar_width
443
441
label_rectangle_widths_color .append (label_rectangle_width_temp )
444
442
label_rectangle_ratio_color_centers .append ((label_rectangle_width_color_total [idx ] + label_rectangle_width_temp / 2 ) / label_rectangle_widths [idx ])
445
443
label_rectangle_width_color_total [idx ] += label_rectangle_width_temp
446
444
idx += 1
447
-
448
445
if not label_rectangle_vertical :
449
446
xs , ys = label_rectangle_painter .get_coordinates (label_rectangle_left_center_pts , label_rectangle_right_center_pts , label_rectangle_widths )
450
447
color_left_center_pts , color_right_center_pts = label_rectangle_painter .get_center_highlight (xs , ys ,
@@ -535,6 +532,7 @@ def _gen_coordinate(self, start, n, edge, spacing, total_range, val_type="str"):
535
532
coor_lst .append (total_range + (start - edge ) - edge )
536
533
return coor_lst
537
534
535
+ # using the variable with the largest number of values as the criteria for same_scale
538
536
def _get_same_scale_minmax (self , original_unique_value ):
539
537
min , max = 0 , 0
540
538
for i , varname in enumerate (self .same_scale ):
@@ -583,6 +581,8 @@ def _list_labels(self, ax, figsize_y, figsize_x, label):
583
581
for v in sorted_unique_valnames_temp :
584
582
if v in unique_valnames :
585
583
sorted_unique_valnames .append (v )
584
+ else :
585
+ sorted_unique_valnames .append (self .same_scale_placeholder )
586
586
if self .missing_data_placeholder in unique_valnames :
587
587
unique_valnames .remove (self .missing_data_placeholder )
588
588
sorted_unique_valnames = sorted (
@@ -649,6 +649,8 @@ def _list_labels(self, ax, figsize_y, figsize_x, label):
649
649
650
650
# plot labels
651
651
for i , (val , y ) in enumerate (zip (uni_val , uni_val_coordinates )):
652
+ if val [1 ] == self .same_scale_placeholder :
653
+ continue
652
654
if label :
653
655
if self .missing and val [1 ] == self .missing_data_placeholder :
654
656
ax .text (x , y , "missing" , ha = 'center' , va = 'center' )
@@ -684,6 +686,8 @@ def _parse_colors(self, color_list):
684
686
685
687
return parsed_colors
686
688
689
+ import math
690
+
687
691
def _compute_left_right_centers (self , midpoints_top , midpoints_bottom , lengths ):
688
692
"""
689
693
Given the top and bottom midpoints of one or more aligned rectangles, along with their width,
0 commit comments