How to use the proplot.internals.docstring function in proplot

To help you get started, we’ve selected a few proplot 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 lukelbd / proplot / proplot / ticker.py View on Github external
    @docstring.add_snippets
    def __call__(self, x, pos=None):  # noqa: U100
        """
        %(formatter.call)s
        """
        # Limit digits to significant figures
        if x == 0:
            digits = 0
        else:
            digits = -int(np.log10(abs(x)) // 1)
        decimal_point = AutoFormatter._get_default_decimal_point()
        digits += self._sigfig - 1
        x = np.round(x, digits)
        string = ('{:.%df}' % max(0, digits)).format(x)
        string = string.replace('.', decimal_point)

        # Custom string formatting
github lukelbd / proplot / proplot / axes / cartesian.py View on Github external
    @docstring.add_snippets
    def dualx(self, funcscale, **kwargs):
        """
        %(axes.dualx)s
        """
        # NOTE: Matplotlib 3.1 has a 'secondary axis' feature. For the time
        # being, our version is more robust (see FuncScale) and simpler, since
        # we do not create an entirely separate _SecondaryAxis class.
        ax = self.altx(**kwargs)
        self._dualx_funcscale = funcscale
        self._dualx_overrides()
        return ax
github lukelbd / proplot / proplot / utils.py View on Github external
color : str, 3-tuple, or 4-tuple
    The color specification. Can be a tuple of channel values, a hex string,
    a registered color name, a cycle color like ``'C0'``, or a colormap color
    (see `~proplot.colors.ColorDatabase`).

    If `space` is ``'rgb'``, this is a tuple of RGB values, and if any
    channels are larger than ``2``, the channels are assumed to be on
    the ``0`` to ``255`` scale and are divided by ``255``.
space : {'rgb', 'hsv', 'hcl', 'hpl', 'hsl'}, optional
    The colorspace for the input channel values. Ignored unless `color` is
    a tuple of numbers.
cycle : str or list, optional
    The registered color cycle name used to interpret colors that
    look like ``'C0'``, ``'C1'``, etc. Default is :rc:`cycle`.
"""
docstring.snippets['param.space'] = """
space : {'hcl', 'hpl', 'hsl', 'hsv'}, optional
    The hue-saturation-luminance-like colorspace used to transform the color.
    Default is the perceptually uniform colorspace ``'hcl'``.
"""

# Shared return values
docstring.snippets['return.rgb'] = """
color : 3-tuple
    An RGB tuple.
"""
docstring.snippets['return.rgba'] = """
color : 4-tuple
    An RGBA tuple.
"""

github lukelbd / proplot / proplot / colors.py View on Github external
    @docstring.add_snippets
    def __init__(
        self, name, segmentdata, N=None, gamma=1,
        cyclic=False, alpha=None,
    ):
        """
        Parameters
        ----------
        %(cmap.init)s
        gamma : float, optional
            Gamma scaling used for the *x* coordinates.
        """
        N = _not_none(N, rcParams['image.lut'])
        super().__init__(name, segmentdata, N=N, gamma=gamma)
        self._cyclic = cyclic
        if alpha is not None:
            self.set_alpha(alpha)
github lukelbd / proplot / proplot / ticker.py View on Github external
__all__ = [
    'AutoFormatter',
    'FracFormatter',
    'LongitudeLocator',
    'LatitudeLocator',
    'SciFormatter',
    'SigFigFormatter',
    'SimpleFormatter',
]

REGEX_ZERO = re.compile('\\A[-\N{MINUS SIGN}]?0(.0*)?\\Z')
REGEX_MINUS = re.compile('\\A[-\N{MINUS SIGN}]\\Z')
REGEX_MINUS_ZERO = re.compile('\\A[-\N{MINUS SIGN}]0(.0*)?\\Z')

docstring.snippets['formatter.params'] = """
zerotrim : bool, optional
    Whether to trim trailing zeros. Default is :rc:`formatter.zerotrim`.
tickrange : (float, float), optional
    Range within which major tick marks are labelled. Default is
    ``(-np.inf, np.inf)``.
wraprange : (float, float), optional
    Range outside of which tick values are wrapped. For example, ``(0, 2)``
    will format a value of ``2.5`` as ``0.5``, and ``(-180, 180)`` will
    format a value of ``200`` as ``-180 + 20 == -160``.
prefix, suffix : str, optional
    Prefix and suffix for all tick strings.
negpos : str, optional
    Length-2 string indicating the suffix for "negative" and "positive"
    numbers, meant to replace the minus sign.
"""
github lukelbd / proplot / proplot / axes / cartesian.py View on Github external
{args} : optional
    Prepended with ``'{x}'`` and passed to `Axes.format`.
"""

_alt_kwargs = (  # TODO: More systematic approach?
    'lim', 'reverse', 'scale', 'label',
    'tickdir', 'grid', 'gridminor',
    'tickminor', 'ticklabeldir', 'tickrange', 'wraprange',
    'rotation', 'formatter', 'ticklabels',
    'ticks', 'locator', 'minorticks', 'minorlocator',
    'bounds', 'margin', 'color',
    'ticklen', 'linewidth', 'gridcolor',
    'label_kw', 'scale_kw', 'locator_kw', 'formatter_kw', 'minorlocator_kw',
)

docstring.snippets['axes.altx'] = _alt_doc.format(
    x='x',
    x1='bottom',
    x2='top',
    y='y',
    y1='left',
    y2='right',
    args=', '.join(_alt_kwargs),
    xargs=', '.join('x' + key for key in _alt_kwargs),
)

docstring.snippets['axes.alty'] = _alt_doc.format(
    x='y',
    x1='left',
    x2='right',
    y='x',
    y1='bottom',
github lukelbd / proplot / proplot / axes / cartesian.py View on Github external
Parameters
----------
{xargs} : optional
    Passed to `Axes.format`.
{args} : optional
    Prepended with ``'{x}'`` and passed to `Axes.format`.
"""

docstring.snippets['axes.twinx'] = _twin_doc.format(
    x='y', x1='left', x2='right',
    y='x', y1='bottom', y2='top',
    args=', '.join(_alt_kwargs),
    xargs=', '.join('y' + key for key in _alt_kwargs),
)
docstring.snippets['axes.twiny'] = _twin_doc.format(
    x='x', x1='bottom', x2='top',
    y='y', y1='left', y2='right',
    args=', '.join(_alt_kwargs),
    xargs=', '.join('x' + key for key in _alt_kwargs),
)


def _parse_alt(x, kwargs):
    """
    Interpret keyword args passed to all "twin axis" methods so they
    can be passed to Axes.format.
    """
    kw_bad, kw_out = {}, {}
    for key, value in kwargs.items():
        if key in _alt_kwargs:
            kw_out[x + key] = value
github lukelbd / proplot / proplot / config.py View on Github external
'red': (1, 0, 0),
    'cyan': (0, 0.75, 0.75),
    'magenta': (0.75, 0, 0.75),
    'yellow': (0.75, 0.75, 0),
    'black': (0, 0, 0),
    'white': (1, 1, 1),
}

_config_docstring = """
user : bool, optional
    Whether to reload user {name}. Default is ``True``.
default : bool, optional
    Whether to reload default proplot {name}. Default is ``False``.
"""
docstring.snippets['register_cmaps.params'] = _config_docstring.format(name='colormaps')
docstring.snippets['register_cycles.params'] = _config_docstring.format(name='cycles')
docstring.snippets['register_colors.params'] = _config_docstring.format(name='colors')
docstring.snippets['rc.params'] = """
local : bool, optional
    Whether to reload ``.proplotrc`` settings in this directory and parent
    directories. Default is ``True``.
user : bool, optional
    Whether to reload ``~/.proplotrc`` user settings. Default is ``True``.
default : bool, optional
    Whether to reload default proplot settings. Default is ``True``.
"""

docstring.snippets['register.ext_table'] = """
Valid file extensions are as follows:

==================  =====================================================================================================================================================================================================================
Extension           Description
github lukelbd / proplot / proplot / demos.py View on Github external
# NOTE: Do not include 'solarized' because colors are terrible for
        # colorblind folks.
        'colorblind', 'colorblind10', 'tableau', 'ggplot', '538', 'seaborn', 'bmh',
    ),
    'ColorBrewer2.0 qualitative': (
        'Accent', 'Dark2',
        'Paired', 'Pastel1', 'Pastel2',
        'Set1', 'Set2', 'Set3',
        'tab10', 'tab20', 'tab20b', 'tab20c',
    ),
    'Other qualitative': (
        'FlatUI', 'Qual1', 'Qual2',
    ),
}

docstring.snippets['show.colorbars'] = """
length : float or str, optional
    The length of the colorbars. Units are interpreted by
    `~proplot.utils.units`.
width : float or str, optional
    The width of the colorbars. Units are interpreted by
    `~proplot.utils.units`.
"""
docstring.snippets['color.categories'] = ', '.join(
    f'``{cat!r}``' for cat in COLORS_TABLE
)
docstring.snippets['cmap.categories'] = ', '.join(
    f'``{cat!r}``' for cat in CMAPS_TABLE
)
docstring.snippets['cycle.categories'] = ', '.join(
    f'``{cat!r}``' for cat in CYCLES_TABLE
)
github lukelbd / proplot / proplot / axes / base.py View on Github external
    @docstring.add_snippets
    def panel_axes(self, side, **kwargs):
        """
        %(axes.panel)s
        """
        side = self._loc_translate(side, 'panel')
        return self.figure._add_axes_panel(self, side, **kwargs)