MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _create_lookup_table

Function _create_lookup_table

lib/matplotlib/colors.py:607–702  ·  view source on GitHub ↗

r""" Create an *N* -element 1D lookup table. This assumes a mapping :math:`f : [0, 1] \rightarrow [0, 1]`. The returned data is an array of N values :math:`y = f(x)` where x is sampled from [0, 1]. By default (*gamma* = 1) x is equidistantly sampled from [0, 1]. The *gamma*

(N, data, gamma=1.0)

Source from the content-addressed store, hash-verified

605
606
607def _create_lookup_table(N, data, gamma=1.0):
608 r"""
609 Create an *N* -element 1D lookup table.
610
611 This assumes a mapping :math:`f : [0, 1] \rightarrow [0, 1]`. The returned
612 data is an array of N values :math:`y = f(x)` where x is sampled from
613 [0, 1].
614
615 By default (*gamma* = 1) x is equidistantly sampled from [0, 1]. The
616 *gamma* correction factor :math:`\gamma` distorts this equidistant
617 sampling by :math:`x \rightarrow x^\gamma`.
618
619 Parameters
620 ----------
621 N : int
622 The number of elements of the created lookup table; at least 1.
623
624 data : (M, 3) array-like or callable
625 Defines the mapping :math:`f`.
626
627 If a (M, 3) array-like, the rows define values (x, y0, y1). The x
628 values must start with x=0, end with x=1, and all x values be in
629 increasing order.
630
631 A value between :math:`x_i` and :math:`x_{i+1}` is mapped to the range
632 :math:`y^1_{i-1} \ldots y^0_i` by linear interpolation.
633
634 For the simple case of a y-continuous mapping, y0 and y1 are identical.
635
636 The two values of y are to allow for discontinuous mapping functions.
637 E.g. a sawtooth with a period of 0.2 and an amplitude of 1 would be::
638
639 [(0, 1, 0), (0.2, 1, 0), (0.4, 1, 0), ..., [(1, 1, 0)]
640
641 In the special case of ``N == 1``, by convention the returned value
642 is y0 for x == 1.
643
644 If *data* is a callable, it must accept and return numpy arrays::
645
646 data(x : ndarray) -> ndarray
647
648 and map values between 0 - 1 to 0 - 1.
649
650 gamma : float
651 Gamma correction factor for input distribution x of the mapping.
652
653 See also https://en.wikipedia.org/wiki/Gamma_correction.
654
655 Returns
656 -------
657 array
658 The lookup table where ``lut[x * (N-1)]`` gives the closest value
659 for values of x between 0 and 1.
660
661 Notes
662 -----
663 This function is internally used for `.LinearSegmentedColormap`.
664 """

Callers 1

_initMethod · 0.85

Calls 1

clipMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…