in python-package/lets_plot/plot/scale.py [0:0]
def scale_manual(aesthetic, values, *,
name=None, breaks=None, labels=None, lablim=None, limits=None, na_value=None, guide=None, format=None):
"""
Create your own discrete scale for the specified aesthetics.
Parameters
----------
aesthetic : str or list
The name(s) of the aesthetic(s) that this scale works with.
values : list of str or dict
A set of aesthetic values to map data values to.
If this is a list, the values will be matched in order (usually alphabetical) with the limits of the scale.
If a dictionary, then the values will be matched based on the names.
name : str
The name of the scale - used as the axis label or the legend title.
If None, the default, the name of the scale
is taken from the first mapping used for that aesthetic.
breaks : list or dict
A list of data values specifying the positions of ticks, or a dictionary which maps the tick labels to the breaks values.
labels : list of str or dict
A list of labels on ticks, or a dictionary which maps the breaks values to the tick labels.
lablim : int, default=None
The maximum label length (in characters) before trimming is applied.
limits : list
Continuous scale: a numeric vector of length two providing limits of the scale.
Discrete scale: a vector specifying the data range for the scale
and the default order of their display in guides.
na_value
Missing values will be replaced with this value.
guide
Guide to use for this scale. It can either be a string ('colorbar', 'legend')
or a call to a guide function (`guide_colorbar() <https://lets-plot.org/python/pages/api/lets_plot.guide_colorbar.html>`__, `guide_legend() <https://lets-plot.org/python/pages/api/lets_plot.guide_legend.html>`__)
specifying additional arguments. 'none' will hide the guide.
format : str
Define the format for labels on the scale. The syntax resembles Python's:
- '.2f' -> '12.45'
- 'Num {}' -> 'Num 12.456789'
- 'TTL: {.2f}$' -> 'TTL: 12.45$'
For more info see `Formatting <https://lets-plot.org/python/pages/formats.html>`__.
Returns
-------
``FeatureSpec`` or ``FeatureSpecArray``
Scales specification.
Notes
-----
Create your own scales for the specified aesthetics.
Examples
--------
.. jupyter-execute::
:linenos:
:emphasize-lines: 6-7
from lets_plot import *
LetsPlot.setup_html()
x = list(range(9))
ggplot({'x': x, 'y': x}, aes('x', 'y')) + \\
geom_point(aes(color='x', fill='x'), shape=21, size=5) + \\
scale_manual(aesthetic=['color', 'fill'], values=['red', 'green', 'blue'], name='color', \\
breaks=[2, 4, 7], labels=['red', 'green', 'blue'])
"""
# 'values' - dict of limits or breaks as keys and values as values
if isinstance(values, dict):
if breaks is None and limits is None:
breaks = list(values.keys())
values = list(values.values())
else:
base_order = breaks if limits is None else limits
if isinstance(base_order, dict):
base_order = list(base_order.values())
new_values = [values[break_value] for break_value in base_order if break_value in values]
if new_values:
no_match_values = list(set(values.values()) - set(new_values)) # doesn't preserve order
values = new_values + no_match_values
else:
values = None
return _scale(aesthetic,
name=name,
breaks=breaks,
labels=labels,
lablim=lablim,
limits=limits,
na_value=na_value,
guide=guide,
format=format,
#
values=values)