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