Skip to content

Commit

Permalink
[Doc] Add Reverse Scale and Update Example for Consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiaLingWeng committed Oct 16, 2023
1 parent 182a310 commit 3672349
Showing 1 changed file with 46 additions and 20 deletions.
66 changes: 46 additions & 20 deletions doc/user_guide/customization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -472,38 +472,64 @@ can be passed to the `scheme` argument of the :class:`Scale` class:

.. altair-plot::

import altair as alt
from vega_datasets import data
import altair as alt
from vega_datasets import data

iris = data.iris()
car = data.cars()

alt.Chart(iris).mark_point().encode(
x='petalWidth',
y='petalLength',
color=alt.Color('species').scale(scheme='dark2')
)
alt.Chart(car).mark_point().encode(
x='Horsepower',
y='Miles_per_Gallon',
color=alt.Color('Acceleration').scale(scheme="spectral")
)

In this example, if we want to match the higher `Acceleration` data to red color,
we can use the `reverse` parameter to reverse the color scheme:

.. altair-plot::

alt.Chart(car).mark_point().encode(
x='Horsepower',
y='Miles_per_Gallon',
color=alt.Color('Acceleration').scale(scheme="spectral", reverse=True)
)

Color Domain and Range
~~~~~~~~~~~~~~~~~~~~~~

To make a custom mapping of discrete values to colors, use the
`domain` and `range` parameters of the :class:`Scale` class for
To specify values to continuous scales,
use the `domain` and `range` parameters of the :class:`Scale` class for
values and colors respectively.

.. altair-plot::

import altair as alt
from vega_datasets import data
import altair as alt
from vega_datasets import data

iris = data.iris()
domain = ['setosa', 'versicolor', 'virginica']
range_ = ['red', 'green', 'blue']
domain = [10, 15, 20]
range_ = ['green', 'blue', 'red']

alt.Chart(iris).mark_point().encode(
x='petalWidth',
y='petalLength',
color=alt.Color('species').scale(domain=domain, range=range_)
)
alt.Chart(car).mark_point().encode(
x='Horsepower:Q',
y='Miles_per_Gallon:Q',
color=alt.Color('Acceleration:Q').scale(domain=domain, range=range_)
)

For discrete scales, we could make a custom mapping of discrete values to colors:

.. altair-plot::

import altair as alt
from vega_datasets import data

domain = ['Europe', "Japan", "USA"]
range_ = ['green', 'blue','red']

alt.Chart(car).mark_point().encode(
x='Horsepower:Q',
y='Miles_per_Gallon:Q',
color=alt.Color('Origin:N').scale(domain=domain, range=range_)
)

Raw Color Values
~~~~~~~~~~~~~~~~
Expand Down

0 comments on commit 3672349

Please sign in to comment.