(self)
Remove the existing density plot (if there is one) and replace it
        with a new one (if enabled).

        The method gets the colors from the pens of the currently plotted
        points.
Remove the existing density plot (if there is one) and replace it
        with a new one (if enabled).
Remove the existing density plot ( if there is one ) and replace it with a new one ( if enabled ) .
def update_density(self):
        """
        Remove the existing density plot (if there is one) and replace it
        with a new one (if enabled).

        The method gets the colors from the pens of the currently plotted
        points.
        """
        if self.density_img:
            self.plot_widget.removeItem(self.density_img)
            self.density_img = None
        if self.class_density and self.scatterplot_item is not None:
            c_data = self.master.get_color_data()
            if c_data is None:
                return
            visible_c_data = self._filter_visible(c_data)
            mask = np.isfinite(visible_c_data)
            if not self.master.is_continuous_color():
                mask = np.bitwise_and(mask, visible_c_data < MAX_COLORS - 1)
            pens = self.scatterplot_item.data['pen']
            rgb_data = [
                pen.color().getRgb()[:3] if pen is not None else (255, 255, 255)
                for known, pen in zip(mask, pens)
                if known]
            if len(set(rgb_data)) <= 1:
                return
            [min_x, max_x], [min_y, max_y] = self.view_box.viewRange()
            x_data, y_data = self.scatterplot_item.getData()
            self.density_img = classdensity.class_density_image(
                min_x, max_x, min_y, max_y, self.resolution,
                x_data[mask], y_data[mask], rgb_data)
            self.plot_widget.addItem(self.density_img, ignoreBounds=True)
def update_density ( self ) : if self . density_img : self . plot_widget . removeItem ( self . density_img ) self . density_img = None if self . class_density and self . scatterplot_item is not None : c_data = self . master . get_color_data ( ) if c_data is None : return visible_c_data = self . _filter_visible ( c_data ) mask = np . isfinite ( visible_c_data ) if not self . master . is_continuous_color ( ) : mask = np . bitwise_and ( mask , visible_c_data < MAX_COLORS - 1 ) pens = self . scatterplot_item . data [ 'pen' ] rgb_data = [ pen . color ( ) . getRgb ( ) [ : 3 ] if pen is not None else ( 255 , 255 , 255 ) for known , pen in zip ( mask , pens ) if known ] if len ( set ( rgb_data ) ) <= 1 : return [ min_x , max_x ] , [ min_y , max_y ] = self . view_box . viewRange ( ) x_data , y_data = self . scatterplot_item . getData ( ) self . density_img = classdensity . class_density_image ( min_x , max_x , min_y , max_y , self . resolution , x_data [ mask ] , y_data [ mask ] , rgb_data ) self . plot_widget . addItem ( self . density_img , ignoreBounds = True )