How to use the yellowbrick.style.palettes.color_palette function in yellowbrick

To help you get started, we’ve selected a few yellowbrick examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DistrictDataLabs / yellowbrick / tests / test_style / test_palettes.py View on Github external
def test_big_palette_context(self):
        """
        Test that the context manager also resets the number of colors
        """

        original_pal = color_palette("accent", n_colors=8)
        context_pal = color_palette("bold", 10)

        set_palette(original_pal)
        with color_palette(context_pal, 10):
            self.assertEqual(get_color_cycle(), context_pal)

        self.assertEqual(get_color_cycle(), original_pal)

        # Reset default
        set_aesthetic()
github DistrictDataLabs / yellowbrick / tests / test_style / test_palettes.py View on Github external
def test_palette_context(self):
        """
        Test the context manager for the color_palette function
        """

        default_pal = color_palette()
        context_pal = color_palette("muted")

        with color_palette(context_pal):
            self.assertEqual(get_color_cycle(), context_pal)

        self.assertEqual(get_color_cycle(), default_pal)
github DistrictDataLabs / yellowbrick / tests / test_style / test_palettes.py View on Github external
def test_color_palette_context(self):
        """
        Test ColorPalette context management
        """
        default = color_palette()
        context = color_palette('dark')

        with ColorPalette('dark') as palette:
            self.assertIsInstance(palette, ColorPalette)
            self.assertEqual(get_color_cycle(), context)

        self.assertEqual(get_color_cycle(), default)
github DistrictDataLabs / yellowbrick / tests / test_style / test_palettes.py View on Github external
def test_big_palette_context(self):
        """
        Test that the context manager also resets the number of colors
        """

        original_pal = color_palette("accent", n_colors=8)
        context_pal = color_palette("bold", 10)

        set_palette(original_pal)
        with color_palette(context_pal, 10):
            self.assertEqual(get_color_cycle(), context_pal)

        self.assertEqual(get_color_cycle(), original_pal)

        # Reset default
        set_aesthetic()
github DistrictDataLabs / yellowbrick / tests / test_style / test_palettes.py View on Github external
def test_palette_context(self):
        """
        Test the context manager for the color_palette function
        """

        default_pal = color_palette()
        context_pal = color_palette("muted")

        with color_palette(context_pal):
            self.assertEqual(get_color_cycle(), context_pal)

        self.assertEqual(get_color_cycle(), default_pal)
github DistrictDataLabs / yellowbrick / tests / test_style / test_palettes.py View on Github external
def test_palette_is_list_of_tuples(self):
        """
        Assert that color_palette returns a list of RGB tuples
        """

        pal_in = np.array(["red", "blue", "green"])
        pal_out = color_palette(pal_in, 3)

        self.assertIsInstance(pal_out, list)
        self.assertIsInstance(pal_out[0], tuple)
        self.assertIsInstance(pal_out[0][0], float)
        self.assertEqual(len(pal_out[0]), 3)
github DistrictDataLabs / yellowbrick / tests / test_style / test_palettes.py View on Github external
def test_color_codes(self):
        """
        Test the setting of color codes
        """
        set_color_codes("accent")
        colors = color_palette("accent") + ["0.06666666666666667"]
        for code, color in zip("bgrmyck", colors):
            rgb_want = mpl.colors.colorConverter.to_rgb(color)
            rgb_got = mpl.colors.colorConverter.to_rgb(code)
            self.assertEqual(rgb_want, rgb_got)
        set_color_codes("reset")
github DistrictDataLabs / yellowbrick / tests / test_style / test_palettes.py View on Github external
def test_preserved_palette_length(self):
        """
        Test palette length is preserved when modified
        """
        pal_in = color_palette("Set1", 10)
        pal_out = color_palette(pal_in)
        self.assertEqual(pal_in, pal_out)
github DistrictDataLabs / yellowbrick / yellowbrick / classifier / base.py View on Github external
per class based on the matplotlib color cycle. If the visualizer is not
        fitted, raises a NotFitted exception.

        If subclasses require users to choose colors or have specialized color
        handling, they should set ``_colors`` on init or during fit.

        Notes
        -----
        Because this is a property, this docstring is for developers only.
        """
        if not hasattr(self, "_colors"):
            if not hasattr(self, "classes_"):
                raise NotFitted("cannot determine colors before fit")

            # TODO: replace with resolve_colors
            self._colors = color_palette(None, len(self.classes_))
        return self._colors
github DistrictDataLabs / yellowbrick / yellowbrick / style / rcmod.py View on Github external
Set the matplotlib color cycle using a seaborn palette.

    Parameters
    ----------
    palette : yellowbrick color palette | seaborn color palette (with ``sns_`` prepended)
        Palette definition. Should be something that :func:`color_palette`
        can process.
    n_colors : int
        Number of colors in the cycle. The default number of colors will depend
        on the format of ``palette``, see the :func:`color_palette`
        documentation for more information.
    color_codes : bool
        If ``True`` and ``palette`` is a seaborn palette, remap the shorthand
        color codes (e.g. "b", "g", "r", etc.) to the colors from this palette.
    """
    colors = color_palette(palette, n_colors)
    if mpl_ge_150:
        from cycler import cycler

        cyl = cycler("color", colors)
        mpl.rcParams["axes.prop_cycle"] = cyl
    else:
        mpl.rcParams["axes.color_cycle"] = list(colors)
    mpl.rcParams["patch.facecolor"] = colors[0]
    if color_codes:
        set_color_codes(palette)