(self)
return colors
Compute colors for different kinds of histograms.
Compute colors for different kinds of histograms.
Compute colors for different kinds of histograms .
def _get_colors(self):
        """Compute colors for different kinds of histograms."""
        target = self.target_var
        if target and target.is_discrete:
            colors = [list(target.palette)[:len(target.values)]] * self.n_bins

        elif self.target_var and self.target_var.is_continuous:
            palette = self.target_var.palette

            bins = np.arange(self.n_bins)[:, np.newaxis]
            edges = self.edges if self.attribute.is_discrete else self.edges[1:-1]
            bin_indices = ut.digitize(self.x, bins=edges)
            mask = bin_indices == bins

            colors = []
            for bin_idx in range(self.n_bins):
                biny = self.y[mask[bin_idx]]
                if np.isfinite(biny).any():
                    mean = ut.nanmean(biny) / ut.nanmax(self.y)
                else:
                    mean = 0  # bin is empty, color does not matter
                colors.append([palette.value_to_qcolor(mean)])

        else:
            colors = [[QColor('#ccc')]] * self.n_bins

        return colors
def _get_colors ( self ) : target = self . target_var if target and target . is_discrete : colors = [ list ( target . palette ) [ : len ( target . values ) ] ] * self . n_bins elif self . target_var and self . target_var . is_continuous : palette = self . target_var . palette bins = np . arange ( self . n_bins ) [ : , np . newaxis ] edges = self . edges if self . attribute . is_discrete else self . edges [ 1 : - 1 ] bin_indices = ut . digitize ( self . x , bins = edges ) mask = bin_indices == bins colors = [ ] for bin_idx in range ( self . n_bins ) : biny = self . y [ mask [ bin_idx ] ] if np . isfinite ( biny ) . any ( ) : mean = ut . nanmean ( biny ) / ut . nanmax ( self . y ) else : mean = 0 # bin is empty, color does not matter colors . append ( [ palette . value_to_qcolor ( mean ) ] ) else : colors = [ [ QColor ( '#ccc' ) ] ] * self . n_bins return colors