8000 Backport PR #14243: Update docstring of makeMappingArray · matplotlib/matplotlib@a8fe4d0 · GitHub
[go: up one dir, main page]

Skip to content

Commit a8fe4d0

Browse files
tacaswellMeeseeksDev[bot]
authored andcommitted
Backport PR #14243: Update docstring of makeMappingArray
1 parent 3b26ee6 commit a8fe4d0

File tree

1 file changed

+54
-18
lines changed

1 file changed

+54
-18
lines changed

lib/matplotlib/colors.py

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -334,24 +334,60 @@ class ColorConverter(object):
334334

335335

336336
def makeMappingArray(N, data, gamma=1.0):
337-
"""Create an *N* -element 1-d lookup table
338-
339-
*data* represented by a list of x,y0,y1 mapping correspondences.
340-
Each element in this list represents how a value between 0 and 1
341-
(inclusive) represented by x is mapped to a corresponding value
342-
between 0 and 1 (inclusive). The two values of y are to allow
343-
for discontinuous mapping functions (say as might be found in a
344-
sawtooth) where y0 represents the value of y for values of x
345-
<= to that given, and y1 is the value to be used for x > than
346-
that given). The list must start with x=0, end with x=1, and
347-
all values of x must be in increasing order. Values between
348-
the given mapping points are determined by simple linear interpolation.
349-
350-
Alternatively, data can be a function mapping values between 0 - 1
351-
to 0 - 1.
352-
353-
The function returns an array "result" where ``result[x*(N-1)]``
354-
gives the closest value for values of x between 0 and 1.
337+
r"""Create an *N* -element 1-d lookup table.
338+
339+
This assumes a mapping :math:`f : [0, 1] \rightarrow [0, 1]`. The returned
340+
data is an array of N values :math:`y = f(x)` where x is sampled from
341+
[0, 1].
342+
343+
By default (*gamma* = 1) x is equidistantly sampled from [0, 1]. The
344+
*gamma* correction factor :math:`\gamma` distorts this equidistant
345+
sampling by :math:`x \rightarrow x^\gamma`.
346+
347+
Parameters
348+
----------
349+
N : int
350+
The number of elements of the created lookup table.
351+
This must be N >= 1.
352+
data : Mx3 array-like or callable
353+
Defines the mapping :math:`f`.
354+
355+
If a Mx3 array-like, the rows define values (x, y0, y1). The x values
356+
must start with x=0, end with x=1, and all x values be in increasing
357+
order.
358+
359+
A value between :math:`x_i` and :math:`x_{i+1}` is mapped to the range
360+
:math:`y^1_{i-1} \ldots y^0_i` by linear interpolation.
361+
362+
For the simple case of a y-continuous mapping, y0 and y1 are identical.
363+
364+
The two values of y are to allow for discontinuous mapping functions.
365+
E.g. a sawtooth with a period of 0.2 and an amplitude of 1 would be::
366+
367+
[(0, 1, 0), (0.2, 1, 0), (0.4, 1, 0), ..., [(1, 1, 0)]
368+
369+
In the special case of ``N == 1``, by convention the returned value
370+
is y0 for x == 1.
371+
372+
If *data* is a callable, it must accept and return numpy arrays::
373+
374+
data(x : ndarray) -> ndarray
375+
376+
and map values between 0 - 1 to 0 - 1.
377+
gamma : float
378+
Gamma correction factor for input distribution x of the mapping.
379+
380+
See also https://en.wikipedia.org/wiki/Gamma_correction.
381+
382+
Returns
383+
-------
384+
lut : array
385+
The lookup table where ``lut[x * (N-1)]`` gives the closest value
386+
for values of x between 0 and 1.
387+
388+
Notes
389+
-----
390+
This function is internally used for `.LinearSegmentedColormaps`.
355391
"""
356392

357393
if callable(data):

0 commit comments

Comments
 (0)
0