33
44.. seealso::
55
6- :doc:`/gallery/color/colormap_reference` for a list of builtin
7- colormaps.
6+ :doc:`/gallery/color/colormap_reference` for a list of builtin colormaps.
87
98 :doc:`/tutorials/colors/colormap-manipulation` for examples of how to
10- make colormaps and
9+ make colormaps.
1110
1211 :doc:`/tutorials/colors/colormaps` an in-depth discussion of
1312 choosing colormaps.
1413
1514 :doc:`/tutorials/colors/colormapnorms` for more details about data
16- normalization
15+ normalization.
1716
1817
1918"""
3736# reversed colormaps have '_r' appended to the name.
3837
3938
40- def _reverser (f , x = None ):
41- """Helper such that ``_reverser(f)(x) == f(1 - x)``."""
42- if x is None :
43- # Returning a partial object keeps it picklable.
44- return functools .partial (_reverser , f )
39+ def _reverser (f , x ): # Toplevel helper for revcmap ensuring cmap picklability.
4540 return f (1 - x )
4641
4742
@@ -50,11 +45,8 @@ def revcmap(data):
5045 data_r = {}
5146 for key , val in data .items ():
5247 if callable (val ):
53- valnew = _reverser (val )
54- # This doesn't work: lambda x: val(1-x)
55- # The same "val" (the first one) is used
56- # each time, so the colors are identical
57- # and the result is shades of gray.
48+ # Return a partial object so that the result is picklable.
49+ valnew = functools .partial (_reverser , val )
5850 else :
5951 # Flip x and exchange the y values facing x = 0 and x = 1.
6052 valnew = [(1.0 - x , y1 , y0 ) for x , y0 , y1 in reversed (val )]
0 commit comments