예제 #1
0
def cycler(*args, **kwargs):
    """
    Create a `~cycler.Cycler` object much like :func:`cycler.cycler`,
    but includes input validation.

    Call signatures::

      cycler(cycler)
      cycler(label=values[, label2=values2[, ...]])
      cycler(label, values)

    Form 1 copies a given `~cycler.Cycler` object.

    Form 2 creates a `~cycler.Cycler` which cycles over one or more
    properties simultaneously. If multiple properties are given, their
    value lists must have the same length.

    Form 3 creates a `~cycler.Cycler` for a single property. This form
    exists for compatibility with the original cycler. Its use is
    discouraged in favor of the kwarg form, i.e. ``cycler(label=values)``.

    Parameters
    ----------
    cycler : Cycler
        Copy constructor for Cycler.

    label : str
        The property key. Must be a valid `.Artist` property.
        For example, 'color' or 'linestyle'. Aliases are allowed,
        such as 'c' for 'color' and 'lw' for 'linewidth'.

    values : iterable
        Finite-length iterable of the property values. These values
        are validated and will raise a ValueError if invalid.

    Returns
    -------
    Cycler
        A new :class:`~cycler.Cycler` for the given properties.

    Examples
    --------
    Creating a cycler for a single property:

    >>> c = cycler(color=['red', 'green', 'blue'])

    Creating a cycler for simultaneously cycling over multiple properties
    (e.g. red circle, green plus, blue cross):

    >>> c = cycler(color=['red', 'green', 'blue'],
    ...            marker=['o', '+', 'x'])

    """
    if args and kwargs:
        raise TypeError("cycler() can only accept positional OR keyword "
                        "arguments -- not both.")
    elif not args and not kwargs:
        raise TypeError("cycler() must have positional OR keyword arguments")

    if len(args) == 1:
        if not isinstance(args[0], Cycler):
            raise TypeError("If only one positional argument given, it must "
                            "be a Cycler instance.")
        return validate_cycler(args[0])
    elif len(args) == 2:
        pairs = [(args[0], args[1])]
    elif len(args) > 2:
        raise TypeError("No more than 2 positional arguments allowed")
    else:
        pairs = kwargs.items()

    validated = []
    for prop, vals in pairs:
        norm_prop = _prop_aliases.get(prop, prop)
        validator = _prop_validators.get(norm_prop, None)
        if validator is None:
            raise TypeError("Unknown artist property: %s" % prop)
        vals = validator(vals)
        # We will normalize the property names as well to reduce
        # the amount of alias handling code elsewhere.
        validated.append((norm_prop, vals))

    return reduce(operator.add, (ccycler(k, v) for k, v in validated))
예제 #2
0
 'axes.formatter.limits': [[-7, 7], validate_nseq_int(2)],
 # use scientific notation if log10
 # of the axis range is smaller than the
 # first or larger than the second
 'axes.formatter.use_locale': [False, validate_bool],
 # Use the current locale to format ticks
 'axes.formatter.use_mathtext': [False, validate_bool],
 'axes.formatter.useoffset': [True, validate_bool],
 'axes.unicode_minus': [True, validate_bool],
 'axes.color_cycle': [['b', 'g', 'r', 'c', 'm', 'y', 'k'],
                      deprecate_axes_colorcycle],  # cycle of plot
 # line colors
 # This entry can be either a cycler object or a
 # string repr of a cycler-object, which gets eval()'ed
 # to create the object.
 'axes.prop_cycle': [ccycler('color', 'bgrcmyk'), validate_cycler],
 # If 'data', axes limits are set close to the data.
 # If 'round_numbers' axes limits are set to the nearest round numbers.
 'axes.autolimit_mode':
 ['data',
  ValidateInStrings('autolimit_mode', ['data', 'round_numbers'])],
 'axes.xmargin':
 [0.05, ValidateInterval(0, 1, closedmin=True,
                         closedmax=True)],  # margin added to xaxis
 'axes.ymargin':
 [0.05, ValidateInterval(0, 1, closedmin=True,
                         closedmax=True)],  # margin added to yaxis
 'polaraxes.grid': [True, validate_bool],  # display polar grid or
 # not
 'axes3d.grid': [True, validate_bool],  # display 3d grid
 # TODO validate that these are valid datetime format strings
예제 #3
0
def cycler(*args, **kwargs):
    """
    Creates a :class:`cycler.Cycler` object much like :func:`cycler.cycler`,
    but includes input validation.

    cyl(arg)
    cyl(label, itr)
    cyl(label1=itr1[, label2=itr2[, ...]])

    Form 1 simply copies a given `Cycler` object.

    Form 2 creates a `Cycler` from a label and an iterable.

    Form 3 composes a `Cycler` as an inner product of the
    pairs of keyword arguments. In other words, all of the
    iterables are cycled simultaneously, as if through zip().

    Parameters
    ----------
    arg : Cycler
        Copy constructor for Cycler.

    label : name
        The property key. Must be a valid `Artist` property.
        For example, 'color' or 'linestyle'. Aliases are allowed,
        such as 'c' for 'color' and 'lw' for 'linewidth'.

    itr : iterable
        Finite-length iterable of the property values. These values
        are validated and will raise a ValueError if invalid.

    Returns
    -------
    cycler : Cycler
        New :class:`cycler.Cycler` for the given properties

    """
    if args and kwargs:
        raise TypeError("cycler() can only accept positional OR keyword "
                        "arguments -- not both.")
    elif not args and not kwargs:
        raise TypeError("cycler() must have positional OR keyword arguments")

    if len(args) == 1:
        if not isinstance(args[0], Cycler):
            raise TypeError("If only one positional argument given, it must "
                            " be a Cycler instance.")

        c = args[0]
        unknowns = c.keys - (set(_prop_validators.keys())
                             | set(_prop_aliases.keys()))
        if unknowns:
            # This is about as much validation I can do
            raise TypeError("Unknown artist properties: %s" % unknowns)
        else:
            return Cycler(c)
    elif len(args) == 2:
        pairs = [(args[0], args[1])]
    elif len(args) > 2:
        raise TypeError("No more than 2 positional arguments allowed")
    else:
        pairs = six.iteritems(kwargs)

    validated = []
    for prop, vals in pairs:
        norm_prop = _prop_aliases.get(prop, prop)
        validator = _prop_validators.get(norm_prop, None)
        if validator is None:
            raise TypeError("Unknown artist property: %s" % prop)
        vals = validator(vals)
        # We will normalize the property names as well to reduce
        # the amount of alias handling code elsewhere.
        validated.append((norm_prop, vals))

    return reduce(operator.add, (ccycler(k, v) for k, v in validated))
예제 #4
0
def cycler(*args, **kwargs):
    """
    Creates a :class:`cycler.Cycler` object much like :func:`cycler.cycler`,
    but includes input validation.

    cyl(arg)
    cyl(label, itr)
    cyl(label1=itr1[, label2=itr2[, ...]])

    Form 1 simply copies a given `Cycler` object.

    Form 2 creates a `Cycler` from a label and an iterable.

    Form 3 composes a `Cycler` as an inner product of the
    pairs of keyword arguments. In other words, all of the
    iterables are cycled simultaneously, as if through zip().

    Parameters
    ----------
    arg : Cycler
        Copy constructor for Cycler.

    label : name
        The property key. Must be a valid `Artist` property.
        For example, 'color' or 'linestyle'. Aliases are allowed,
        such as 'c' for 'color' and 'lw' for 'linewidth'.

    itr : iterable
        Finite-length iterable of the property values. These values
        are validated and will raise a ValueError if invalid.

    Returns
    -------
    cycler : Cycler
        New :class:`cycler.Cycler` for the given properties

    """
    if args and kwargs:
        raise TypeError("cycler() can only accept positional OR keyword "
                        "arguments -- not both.")
    elif not args and not kwargs:
        raise TypeError("cycler() must have positional OR keyword arguments")

    if len(args) == 1:
        if not isinstance(args[0], Cycler):
            raise TypeError("If only one positional argument given, it must "
                            " be a Cycler instance.")

        c = args[0]
        unknowns = c.keys - (set(_prop_validators.keys()) |
                             set(_prop_aliases.keys()))
        if unknowns:
            # This is about as much validation I can do
            raise TypeError("Unknown artist properties: %s" % unknowns)
        else:
            return Cycler(c)
    elif len(args) == 2:
        pairs = [(args[0], args[1])]
    elif len(args) > 2:
        raise TypeError("No more than 2 positional arguments allowed")
    else:
        pairs = six.iteritems(kwargs)

    validated = []
    for prop, vals in pairs:
        norm_prop = _prop_aliases.get(prop, prop)
        validator = _prop_validators.get(norm_prop, None)
        if validator is None:
            raise TypeError("Unknown artist property: %s" % prop)
        vals = validator(vals)
        # We will normalize the property names as well to reduce
        # the amount of alias handling code elsewhere.
        validated.append((norm_prop, vals))

    return reduce(operator.add, (ccycler(k, v) for k, v in validated))
예제 #5
0
    'axes.formatter.limits': [[-7, 7], validate_nseq_int(2)],
                               # use scientific notation if log10
                               # of the axis range is smaller than the
                               # first or larger than the second
    'axes.formatter.use_locale': [False, validate_bool],
                               # Use the current locale to format ticks
    'axes.formatter.use_mathtext': [False, validate_bool],
    'axes.formatter.useoffset': [True, validate_bool],
    'axes.unicode_minus': [True, validate_bool],
    'axes.color_cycle': [['b', 'g', 'r', 'c', 'm', 'y', 'k'],
                         deprecate_axes_colorcycle],  # cycle of plot
                                                      # line colors
    # This entry can be either a cycler object or a
    # string repr of a cycler-object, which gets eval()'ed
    # to create the object.
    'axes.prop_cycle': [ccycler('color', 'bgrcmyk'),
                        validate_cycler],
    # If 'data', axes limits are set close to the data.
    # If 'round_numbers' axes limits are set to the nearest round numbers.
    'axes.autolimit_mode': [
        'data',
        ValidateInStrings('autolimit_mode', ['data', 'round_numbers'])],
    'axes.xmargin': [0.05, ValidateInterval(0, 1,
                                            closedmin=True,
                                            closedmax=True)],  # margin added to xaxis
    'axes.ymargin': [0.05, ValidateInterval(0, 1,
                                            closedmin=True,
                                            closedmax=True)],# margin added to yaxis

    'polaraxes.grid': [True, validate_bool],  # display polar grid or
                                                     # not
예제 #6
0
    'axes.formatter.limits': [[-7, 7], validate_nseq_int(2)],
                               # use scientific notation if log10
                               # of the axis range is smaller than the
                               # first or larger than the second
    'axes.formatter.use_locale': [False, validate_bool],
                               # Use the current locale to format ticks
    'axes.formatter.use_mathtext': [False, validate_bool],
    'axes.formatter.useoffset': [True, validate_bool],
    'axes.unicode_minus': [True, validate_bool],
    'axes.color_cycle': [['b', 'g', 'r', 'c', 'm', 'y', 'k'],
                         deprecate_axes_colorcycle],  # cycle of plot
                                                      # line colors
    # This entry can be either a cycler object or a
    # string repr of a cycler-object, which gets eval()'ed
    # to create the object.
    'axes.prop_cycle': [ccycler('color', 'bgrcmyk'),
                        validate_cycler],
    'axes.xmargin': [0, ValidateInterval(0, 1,
                                         closedmin=True,
                                         closedmax=True)],  # margin added to xaxis
    'axes.ymargin': [0, ValidateInterval(0, 1,
                                         closedmin=True,
                                         closedmax=True)],# margin added to yaxis

    'polaraxes.grid': [True, validate_bool],  # display polar grid or
                                                     # not
    'axes3d.grid': [True, validate_bool],  # display 3d grid

    #legend properties
    'legend.fancybox': [False, validate_bool],
예제 #7
0
                               # of the axis range is smaller than the
                               # first or larger than the second
    'axes.formatter.use_locale': [False, validate_bool],
                               # Use the current locale to format ticks
    'axes.formatter.use_mathtext': [False, validate_bool],
    'axes.formatter.useoffset': [True, validate_bool],
    'axes.unicode_minus': [True, validate_bool],
    'axes.color_cycle': [['b', 'g', 'r', 'c', 'm', 'y', 'k'],
                         deprecate_axes_colorcycle],  # cycle of plot
                                                      # line colors
    # This entry can be either a cycler object or a
    # string repr of a cycler-object, which gets eval()'ed
    # to create the object.
    'axes.prop_cycle': [
        ccycler('color',
                ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728',
                 '#9467bd', '#8c564b', '#e377c2', '#7f7f7f',
                 '#bcbd22', '#17becf']),
        validate_cycler],
    # If 'data', axes limits are set close to the data.
    # If 'round_numbers' axes limits are set to the nearest round numbers.
    'axes.autolimit_mode': [
        'data',
        ValidateInStrings('autolimit_mode', ['data', 'round_numbers'])],
    'axes.xmargin': [0.05, ValidateInterval(0, 1,
                                            closedmin=True,
                                            closedmax=True)],  # margin added to xaxis
    'axes.ymargin': [0.05, ValidateInterval(0, 1,
                                            closedmin=True,
                                            closedmax=True)],# margin added to yaxis

    'polaraxes.grid': [True, validate_bool],  # display polar grid or
예제 #8
0
 "axes.formatter.useoffset": [True, validate_bool],
 "axes.unicode_minus": [True, validate_bool],
 "axes.color_cycle": [["b", "g", "r", "c", "m", "y", "k"], deprecate_axes_colorcycle],  # cycle of plot
 # line colors
 # This entry can be either a cycler object or a
 # string repr of a cycler-object, which gets eval()'ed
 # to create the object.
 "axes.prop_cycle": [
     ccycler(
         "color",
         [
             "#1f77b4",
             "#ff7f0e",
             "#2ca02c",
             "#d62728",
             "#9467bd",
             "#8c564b",
             "#e377c2",
             "#7f7f7f",
             "#bcbd22",
             "#17becf",
         ],
     ),
     validate_cycler,
 ],
 # If 'data', axes limits are set close to the data.
 # If 'round_numbers' axes limits are set to the nearest round numbers.
 "axes.autolimit_mode": ["data", ValidateInStrings("autolimit_mode", ["data", "round_numbers"])],
 "axes.xmargin": [0.05, ValidateInterval(0, 1, closedmin=True, closedmax=True)],  # margin added to xaxis
 "axes.ymargin": [0.05, ValidateInterval(0, 1, closedmin=True, closedmax=True)],  # margin added to yaxis
 "polaraxes.grid": [True, validate_bool],  # display polar grid or