Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

DOC: draft of a full explanation of norm + colormap interactions#18487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
tacaswell wants to merge15 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromtacaswell:doc_floating_point_and_you
Draft
Changes from1 commit
Commits
Show all changes
15 commits
Select commitHold shift + click to select a range
1a30f6a
MNT: move creating interal ScalarMappable to where it is used
tacaswellSep 20, 2020
0aa8586
DOC: draft of a full explanation of norm + colormap interactions
tacaswellSep 15, 2020
e5a255d
DOC: draft text on resampling
tacaswellSep 20, 2020
83209c8
DOC: draft text on floating point and images resampling
tacaswellOct 7, 2020
0123002
DOC: fix link in newly built docstring
tacaswellOct 7, 2020
6af9106
DOC: make the colormap description more colloquial
tacaswellOct 7, 2020
d6867f6
DOC: word-choice in floating point section
tacaswellOct 7, 2020
2d72105
DOC: copy-edits from review
tacaswellOct 9, 2020
e5bf870
ENH: add a repr to Normalize
tacaswellOct 9, 2020
c49b646
DOC: more copy-editing
tacaswellOct 9, 2020
32a2a70
DOC/WIP: reorganization
tacaswellOct 28, 2020
67ed971
DOC: fix a PIL reference
tacaswellAug 14, 2021
ced2552
DOC: fix url
tacaswellAug 14, 2021
c8fa541
DOC: add attributes to Normalize
tacaswellAug 14, 2021
317a6af
DOC: re-write most of the new text
tacaswellAug 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
DOC: draft of a full explanation of norm + colormap interactions
  • Loading branch information
@tacaswell
tacaswell committedAug 14, 2021
commit0aa85863f403cb1f908e038d1de1e8094cb0c449
149 changes: 128 additions & 21 deletionsdoc/api/colors_api.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,42 +14,149 @@
:no-members:
:no-inherited-members:

Classes
-------
Color Conversion tools
----------------------

.. autosummary::
:toctree: _as_gen/
:template: autosummary.rst

is_color_like
same_color

hsv_to_rgb
rgb_to_hsv

to_hex
to_rgb
to_rgba
to_rgba_array

get_named_colors_mapping


Normalization and Colormapping
------------------------------

Some Artists can map an array of input data to RGBA values, (ex
`~.axes.Axes.scatter` or `~.axes.Axes.imshow`). The machinery for
this is implemented via the `~.cm.ScalarMappable` base class in `~.cm`
and the `~.Normalize` and `~.Colormap` classes in this module.

At the core, colormapping is going from a scalar value to a RGB(A) tuple
(formally :math:`f(x) : ℝ^1 \rightarrow ℝ^3`), that is we are tracing some
1D path through the 3D RGB space. This mapping can be separated into two
orthogonal parts:

1. the path through color space
2. the mapping between the users data to distance along the curve.

The first step is expressed in Matplotlib via the `.Colormap` family
of classes and the second step is expressed through the `.Normalize` family
of classes. This allows us to fully independently pick what colors to use (by
selecting the colormap), what data range to show (via the ``vmin`` and ``vmax``
attributes on `.Normalize` or the `.cm.ScalarMappable.set_clim` method), and
the functional transform (ex linear vs log) from data space to distance along the
curve space.

In addition to the colors in the map `.Colormap` objects carry three additional colors

- over (`.Colormap.set_over` / `.Colormap.get_over`)
- under (`.Colormap.set_under` / `.Colormap.get_under`)
- bad (`.Colormap.set_bad` / `.Colormap.get_bad`)

The first two (over / under) control what should be done for values
that are greater or less than the data range set by the user. By
default these are equal to the top and bottom colors of the color map.
The "bad" value is used for masked or non-finite values (e.g. nan and
inf) and defaults to transparent.


.. note::

Using `.cm.get_cmap` may return to you a reference to a globally
visible instance of the colormap (rather than a new instance). If
you plan to set the over/under/bad values we recommend you first
make a copy ::

from copy import copy
import matplotlib.cm as mcm

my_cmap = copy(mcm.get_cmap('viridis'))


Both `.Colormap` and `.Normalize` are implemented as `callable classes
<https://docs.python.org/3/reference/datamodel.html#object.__call__>`__ which
allows use to bind some (mutable) state to a function call. The `.Colormap.__call__`
signature when passed floats ::

def map(X: NormedData, alpha:Optional[float] =None, bytes:Bool=False) -> RGBA:
...

Takes data in a "normalized" space and:

- maps values in the closed set ``[0, 1]`` to that fraction along the curve
- maps any value greater than 1 to the "over" color
- maps any value less than 0 to the "under" color
- maps any non-finite or masked value to the "bad" color

broadcasting to match the input shape (scalar to tuple, n-D array to
(n+1)-D array). This can be useful to get a set of colors drawn from
a color map ::

import matplotlib.cm as mcm
import numpy as np

cmap = mcm.get_cmap('viridis')
list_of_colors = cmap(np.arange(0, 1, 5))



.. autosummary::
:toctree: _as_gen/
:template: autosummary.rst

BoundaryNorm
Colormap
CenteredNorm
LightSource
LinearSegmentedColormap
ListedColormap
LogNorm
NoNorm


.. autosummary::
:toctree: _as_gen/
:template: autosummary.rst

Normalize
LogNorm
CenteredNorm
BoundaryNorm
TwoSlopeNorm
PowerNorm
NoNorm
SymLogNorm
TwoSlopeNorm
FuncNorm

Functions
---------

.. autosummary::
:toctree: _as_gen/
:template: autosummary.rst

from_levels_and_colors
hsv_to_rgb
rgb_to_hsv
to_hex
to_rgb
to_rgba
to_rgba_array
is_color_like
same_color
get_named_colors_mapping
make_norm_from_scale


.. inheritance-diagram:: matplotlib.colors.Colormap matplotlib.colors.LinearSegmentedColormap matplotlib.colors.ListedColormap
:parts: 1
:private-bases:


.. inheritance-diagram:: matplotlib.colors.Normalize matplotlib.colors.LogNorm matplotlib.colors.PowerNorm matplotlib.colors.NoNorm matplotlib.colors.TwoSlopeNorm matplotlib.colors.SymLogNorm matplotlib.colors.BoundaryNorm
:parts: 1
:private-bases:


Hill Shading
------------

.. autosummary::
:toctree: _as_gen/
:template: autosummary.rst

LightSource

[8]ページ先頭

©2009-2025 Movatter.jp