@@ -680,19 +680,22 @@ def _display_changed_disc(self):
680680
681681 self .draw_axis_disc ()
682682 if self .group_var :
683- self .boxes = \
684- [self .strudel (cont , val )
685- for cont , val in zip (self .conts .array_with_unknowns ,
686- self .group_var .values + ("" , ))
687- if np .sum (cont ) > 0 ]
683+ conts = self .conts .array_with_unknowns
684+ self .boxes = [
685+ self .strudel (cont , val )
686+ for cont , val in zip (conts , self .group_var .values + ("" , ))
687+ if np .sum (cont ) > 0
688+ ]
689+ sums_ = np .sum (conts , axis = 1 )
690+ sums_ = sums_ [sums_ > 0 ] # only bars with sum > 0 are shown
688691
689692 if self .sort_freqs :
690693 # pylint: disable=invalid-unary-operand-type
691- self .order = sorted (
692- self .order , key = (- np .sum (
693- self .conts .array_with_unknowns , axis = 1 )).__getitem__ )
694+ self .order = sorted (self .order , key = (- sums_ ).__getitem__ )
694695 else :
695- self .boxes = [self .strudel (self .dist .array_with_unknowns )]
696+ conts = self .dist .array_with_unknowns
697+ self .boxes = [self .strudel (conts )]
698+ sums_ = [np .sum (conts )]
696699
697700 for row , box_index in enumerate (self .order ):
698701 y = (- len (self .boxes ) + row ) * 40 + 10
@@ -701,7 +704,9 @@ def _display_changed_disc(self):
701704
702705 self .__draw_group_labels (y , box_index )
703706 if not self .show_stretched :
704- self .__draw_row_counts (y , box_index )
707+ self .__draw_row_counts (
708+ y , self .labels [box_index ], sums_ [box_index ]
709+ )
705710 if self .show_labels and self .attribute is not self .group_var :
706711 self .__draw_bar_labels (y , bars , labels )
707712 self .__draw_bars (y , bars )
@@ -726,23 +731,21 @@ def __draw_group_labels(self, y, row):
726731 label .setPos (- b .width () - 10 , y - b .height () / 2 )
727732 self .box_scene .addItem (label )
728733
729- def __draw_row_counts (self , y , row ):
734+ def __draw_row_counts (self , y , label , row_sum_ ):
730735 """Draw row counts
731736
732737 Parameters
733738 ----------
734739 y: int
735740 vertical offset of bars
736- row: int
737- row index
741+ label: QGraphicsSimpleTextItem
742+ Label for group
743+ row_sum_: int
744+ Sum for the group
738745 """
739746 assert not self .attribute .is_continuous
740- label = self .labels [row ]
741747 b = label .boundingRect ()
742- if self .group_var :
743- right = self .scale_x * sum (self .conts .array_with_unknowns [row ])
744- else :
745- right = self .scale_x * sum (self .dist )
748+ right = self .scale_x * row_sum_
746749 label .setPos (right + 10 , y - b .height () / 2 )
747750 self .box_scene .addItem (label )
748751
0 commit comments