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

Appearance settings

Commit 1fb0610

Browse filesBrowse files
committed
Simplify colormap reversal.
... plus small docstrings cleanups.
1 parent 04d9d28 commit 1fb0610
Copy full SHA for 1fb0610

File tree

Expand file treeCollapse file tree

1 file changed

+6
-14
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-14
lines changed

‎lib/matplotlib/cm.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cm.py
+6-14Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
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
"""
@@ -37,11 +36,7 @@
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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.