How to use the yellowbrick.style.palettes.ColorPalette 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_init_palette_by_list(self):
        """
        Test that a palette can be initialized by a list
        """

        # Try all the values in the palettes (HEX)
        for value in PALETTES.values():
            palette = ColorPalette(value)
            self.assertEqual(len(value), len(palette))

        # Try all the values converted to RGB
        for value in PALETTES.values():
            palette = ColorPalette(map(mpl.colors.colorConverter.to_rgb, value))
            self.assertEqual(len(value), len(palette))
github DistrictDataLabs / yellowbrick / tests / test_style / test_palettes.py View on Github external
def test_init_palette_by_name(self):
        """
        Test that a palette can be initialized by name
        """

        # Try all the names in the palettes
        for name, value in PALETTES.items():
            try:
                palette = ColorPalette(name)
            except YellowbrickValueError:
                self.fail(
                    "Could not instantiate {} color palette by name".format(name)
                )

            self.assertEqual(value, palette)

        # Try a name not in PALETTES
        with self.assertRaises(YellowbrickValueError):
            self.assertNotIn('foo', PALETTES, "Cannot test bad name 'foo' it is in PALETTES!")
            palette = ColorPalette('foo')
github DistrictDataLabs / yellowbrick / tests / test_style / test_palettes.py View on Github external
def test_init_palette_by_list(self):
        """
        Test that a palette can be initialized by a list
        """

        # Try all the values in the palettes (HEX)
        for value in PALETTES.values():
            palette = ColorPalette(value)
            self.assertEqual(len(value), len(palette))

        # Try all the values converted to RGB
        for value in PALETTES.values():
            palette = ColorPalette(map(mpl.colors.colorConverter.to_rgb, value))
            self.assertEqual(len(value), len(palette))
github DistrictDataLabs / yellowbrick / yellowbrick / style / palettes.py View on Github external
raise YellowbrickValueError(
                "'{}' is not a recognized palette!".format(palette)
            )

        palette = PALETTES[palette.lower()]
        if n_colors is None:
            n_colors = len(palette)

    # Always return as many colors as we asked for
    pal_cycle = cycle(palette)
    palette = [next(pal_cycle) for _ in range(n_colors)]

    # Always return in RGB tuple format
    try:
        palette = map(mpl.colors.colorConverter.to_rgb, palette)
        palette = ColorPalette(palette)
    except ValueError:
        raise YellowbrickValueError(
            "Could not generate a palette for %s" % str(palette)
        )

    return palette
github DistrictDataLabs / yellowbrick / yellowbrick / style / palettes.py View on Github external
Parameters
        ----------

        name_or_list :
            specify a palette name or a list of RGB or Hex values

        """
        if isinstance(name_or_list, str):
            if name_or_list not in PALETTES:
                raise YellowbrickValueError(
                    "'{}' is not a recognized palette!".format(name_or_list)
                )

            name_or_list = PALETTES[name_or_list]

        super(ColorPalette, self).__init__(name_or_list)
github DistrictDataLabs / yellowbrick / yellowbrick / style / palettes.py View on Github external
def as_rgb(self):
        """
        Return a color palette with RGB values instead of hex codes.
        """
        rgb = [mpl.colors.colorConverter.to_rgb(hex) for hex in self]
        return ColorPalette(rgb)
github DistrictDataLabs / yellowbrick / yellowbrick / style / colors.py View on Github external
from .palettes import PALETTES, ColorPalette
        if isinstance(colormap, str):
            try:

                # try to get colormap from PALETTES first
                _colormap = PALETTES.get(colormap, None)

                if _colormap is None:

                    colormap = cm.get_cmap(colormap)
                    n_colors = n_colors or len(get_color_cycle())
                    _colors = list(map(colormap, np.linspace(0, 1, num=n_colors)))

                else:

                    _colors = ColorPalette(_colormap).as_rgb()
                    n_colors = n_colors or len(_colors)

            except ValueError as e:

                raise YellowbrickValueError(e)

        # if yellowbrick color palette is provided as colormap
        elif isinstance(colormap, ColorPalette):

            _colors = colormap.as_rgb()
            n_colors = n_colors or len(_colors)

        # if matplotlib color palette is provided as colormap
        elif isinstance(colormap, mpl.colors.Colormap):
            n_colors = n_colors or len(get_color_cycle())
            _colors = list(map(colormap, np.linspace(0, 1, num=n_colors)))