コード例 #1
0
    def test_decimal_binnings(self):
        values = np.array([
            -0.2, -0.2, -0.6, 1.0, 0.2, -0.6, 0.6, 1.0, 0.4, -0.5, -0.4, -0.4,
            -0.6, 0.6, 0.75, 0.4, -0.2, 0.2, 0.0, 0.0, -1.0, -0.6, -0.2, -0.6,
        ])
        binning = decimal_binnings(values, factors=[0.2, 0.25, 0.5])
        self.assertEqual(len(binning), 3)

        np.testing.assert_array_equal(
            binning[0].thresholds,
            [-1, -0.8, -0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6, 0.8, 1]
        )
        self.assertEqual(binning[0].width, 0.2)

        np.testing.assert_array_equal(
            binning[1].thresholds,
            [-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1]
        )
        self.assertEqual(binning[1].width, 0.25)

        np.testing.assert_array_equal(
            binning[2].thresholds,
            [-1, -0.5, 0, 0.5, 1]
        )
        self.assertEqual(binning[2].width, 0.5)
コード例 #2
0
ファイル: owsom.py プロジェクト: Alexdimas/Orange-Canvas
 def set_color_bins(self):
     if self.attr_color is None:
         self.thresholds = self.colors = None
     elif self.attr_color.is_discrete:
         self.thresholds = None
         self.colors = [QColor(*color) for color in self.attr_color.colors]
     else:
         col = self.data.get_column_view(self.attr_color)[0].astype(float)
         self.thresholds = decimal_binnings(col, min_bins=4)[0][1:-1]
         palette = ContinuousPaletteGenerator(*self.attr_color.colors)
         nbins = len(self.thresholds) + 1
         self.colors = [palette[i / (nbins - 1)] for i in range(nbins)]
コード例 #3
0
 def set_color_bins(self):
     if self.attr_color is None:
         self.thresholds = self.bin_labels = self.colors = None
     elif self.attr_color.is_discrete:
         self.thresholds = self.bin_labels = None
         self.colors = self.attr_color.palette
     else:
         col = self.data.get_column_view(self.attr_color)[0].astype(float)
         if self.attr_color.is_time:
             binning = time_binnings(col, min_bins=4)[-1]
         else:
             binning = decimal_binnings(col, min_bins=4)[-1]
         self.thresholds = binning.thresholds[1:-1]
         self.bin_labels = (binning.labels[1:-1], binning.short_labels[1:-1])
         palette = BinnedContinuousPalette.from_palette(
             self.attr_color.palette, binning.thresholds)
         self.colors = palette
コード例 #4
0
ファイル: owsom.py プロジェクト: szzyiit/orange3
    def set_color_bins(self):
        self.Warning.no_defined_colors.clear()

        if self.attr_color is None:
            self.thresholds = self.bin_labels = self.colors = None
            return

        if self.attr_color.is_discrete:
            self.thresholds = self.bin_labels = None
            self.colors = self.attr_color.palette
            return

        col = self.data.get_column_view(self.attr_color)[0].astype(float)
        col = col[np.isfinite(col)]
        if not col.size:
            self.Warning.no_defined_colors(self.attr_color)
            self.thresholds = self.bin_labels = self.colors = None
            return

        if self.attr_color.is_time:
            binning = time_binnings(col, min_bins=4)[-1]
        else:
            binning = decimal_binnings(col, min_bins=4)[-1]
        self.thresholds = binning.thresholds[1:-1]
        self.bin_labels = (binning.labels[1:-1], binning.short_labels[1:-1])
        if not self.bin_labels[0] and binning.labels:
            # Nan's are already filtered out, but it doesn't hurt much
            # to use nanmax/nanmin
            if np.nanmin(col) == np.nanmax(col):
                # Handle a degenerate case with a single value
                # Use the second threshold (because value must be smaller),
                # but the first threshold as label (because that's the
                # actual value in the data.
                self.thresholds = binning.thresholds[1:]
                self.bin_labels = (binning.labels[:1],
                                   binning.short_labels[:1])
        palette = BinnedContinuousPalette.from_palette(self.attr_color.palette,
                                                       binning.thresholds)
        self.colors = palette