How to use the plotnine.scales.scale.scale_discrete function in plotnine

To help you get started, we’ve selected a few plotnine 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 has2k1 / plotnine / plotnine / scales / scale_color.py View on Github external
from mizani.bounds import rescale_mid
from mizani.palettes import (hue_pal, brewer_pal, grey_pal,
                             gradient_n_pal, cmap_pal, cmap_d_pal,
                             desaturate_pal)

from ..utils import alias
from ..doctools import document
from ..exceptions import PlotnineWarning
from .scale import scale_discrete, scale_continuous, scale_datetime


# Discrete color scales #

# Note: plotnine operates in the hcl space
@document
class scale_color_hue(scale_discrete):
    """
    Qualitative color scale with evenly spaced hues

    Parameters
    ----------
    h : float
        first hue. Must be in the range [0, 1]
        Default is ``0.01``
    l : float
        lightness. Must be in the range [0, 1]
        Default is ``0.6``
    s : float
        saturation. Must be in the range [0, 1]
        Default is ``0.65``
    colorspace : str in ``['hls', 'husl']``
        Color space to use.
github has2k1 / plotnine / plotnine / scales / scale_color.py View on Github external
@document
class scale_fill_cmap(scale_color_cmap):
    """
    Create color scales using Matplotlib colormaps

    Parameters
    ----------
    {superclass_parameters}
    """
    _aesthetics = ['fill']


@document
class scale_color_cmap_d(scale_discrete):
    """
    A discrete color scales using Matplotlib colormaps

    Parameters
    ----------
    name : str
        A standard Matplotlib colormap name. It must be of type
        :class:`matplotlib.colors.ListedColormap`.
        . The default is `viridis`. For the list of names checkout
        the output of ``matplotlib.cm.cmap_d.keys()`` or see the
        `documentation `_.
    lut : None | int
        This is the number of entries desired in the
        lookup table. Default is `None`, leave it up
        Matplotlib.
    {superclass_parameters}
github has2k1 / plotnine / plotnine / scales / scale_color.py View on Github external
@document
class scale_fill_hue(scale_color_hue):
    """
    Qualitative color scale with evenly spaced hues

    Parameters
    ----------
    {superclass_parameters}
    """
    _aesthetics = ['fill']


@document
class scale_color_brewer(scale_discrete):
    """
    Sequential, diverging and qualitative discrete color scales

    See `colorbrewer.org `_

    Parameters
    ----------
    type : str in ``['seq', 'div', 'qual']``
        Type of data. Sequential, diverging or qualitative
    palette : int | str
         If a string, will use that named palette.
         If a number, will index into the list of palettes
         of appropriate type. Default is 1
    {superclass_parameters}
    na_value : str
        Color of missing values. Default is ``'None'``
github has2k1 / plotnine / plotnine / scales / scale_linetype.py View on Github external
from warnings import warn

from mizani.palettes import manual_pal

from ..doctools import document
from ..exceptions import PlotnineError, PlotnineWarning
from ..utils import alias
from .scale import scale_discrete, scale_continuous


linetypes = ['solid', 'dashed', 'dashdot', 'dotted']


@document
class scale_linetype(scale_discrete):
    """
    Scale for line patterns

    Parameters
    ----------
    {superclass_parameters}

    Notes
    -----
    The available linetypes are
    ``'solid', 'dashed', 'dashdot', 'dotted'``
    If you need more custom linetypes, use
    :class:`~plotnine.scales.scale_linetype_manual`
    """
    _aesthetics = ['linetype']
    palette = staticmethod(manual_pal(linetypes))
github has2k1 / plotnine / plotnine / scales / scale_color.py View on Github external
@document
class scale_fill_brewer(scale_color_brewer):
    """
    Sequential, diverging and qualitative color scales

    Parameters
    ----------
    {superclass_parameters}
    """
    _aesthetics = ['fill']


@document
class scale_color_grey(scale_discrete):
    """
    Sequential grey color scale.

    Parameters
    ----------
    start : float
        grey value at low end of palette.
        Default is 0.2
    end : float
        grey value at high end of palette
        Default is 0.8
    {superclass_parameters}
    """
    _aesthetics = ['color']

    def __init__(self, start=0.2, end=0.8, **kwargs):
github has2k1 / plotnine / plotnine / scales / scale_alpha.py View on Github external
def __init__(self, range=(0.1, 1), **kwargs):
        def palette(n):
            return np.linspace(range[0], range[1], n)

        self.palette = palette
        scale_discrete.__init__(self, **kwargs)
github has2k1 / plotnine / plotnine / scales / scale_xy.py View on Github external
from ..doctools import document
from ..utils import identity, match, alias, array_kind
from ..exceptions import PlotnineError
from .range import RangeContinuous
from .scale import scale_discrete, scale_continuous, scale_datetime


# positions scales have a couple of differences (quirks) that
# make necessary to override some of the scale_discrete and
# scale_continuous methods
#
# scale_position_discrete and scale_position_continuous
# are intermediate base classes where the required overriding
# is done
@document
class scale_position_discrete(scale_discrete):
    """
    Base class for discrete position scales

    Parameters
    ----------
    {superclass_parameters}
    limits : array_like, optional
        Limits of the scale. For discrete scale, these are
        the categories (unique values) of the variable.
        For scales that deal with categoricals, these may
        be a subset or superset of the categories.
    """
    # All positions have no guide
    guide = None

    # After transformations all position values map
github has2k1 / plotnine / plotnine / scales / scale_size.py View on Github external
from warnings import warn

import numpy as np
from mizani.bounds import rescale_max
from mizani.palettes import abs_area, area_pal, rescale_pal

from ..doctools import document
from ..exceptions import PlotnineWarning
from ..utils import alias
from .scale import scale_discrete, scale_continuous, scale_datetime


@document
class scale_size_ordinal(scale_discrete):
    """
    Discrete area size scale

    Parameters
    ----------
    range : array_like
        Minimum and maximum size of the plotting symbol.
        It must be of size 2.
    {superclass_parameters}
    """
    _aesthetics = ['size']

    def __init__(self, range=(2, 6), **kwargs):
        def palette(n):
            area = np.linspace(range[0]**2, range[1]**2, n)
            return np.sqrt(area)
github has2k1 / plotnine / plotnine / scales / scale_shape.py View on Github external
'1',  # tri_down
    '2',  # tri_up
    '3',  # tri_left
    '4',  # tri_right
    ',',  # pixel
    '_',  # hline
    '|',  # vline
    1,    # tickleft
    2,    # tickright
    3,    # tickup
    4,    # tickdown
)


@document
class scale_shape(scale_discrete):
    """
    Scale for shapes

    Parameters
    ----------
    unfilled : bool
        If ``True``, then all shapes will have no interiors
        that can be a filled.
    {superclass_parameters}
    """
    _aesthetics = ['shape']

    def __init__(self, unfilled=False, **kwargs):
        if unfilled:
            self.palette = manual_pal(unfilled_shapes)
        else:
github has2k1 / plotnine / plotnine / scales / scale_color.py View on Github external
def __init__(self, h=.01, l=.6, s=.65, color_space='hls', **kwargs):
        self.palette = hue_pal(h, l, s, color_space=color_space)
        scale_discrete.__init__(self, **kwargs)