Skip to content

Commit 00ac131

Browse files
committed
added "lighten" function in tools to allow user to set an alpha value to existing colormap
1 parent d811512 commit 00ac131

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

cmocean/tools.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,21 @@ def cmap(rgbin, N=256):
8989
cmap = mpl.colors.LinearSegmentedColormap.from_list('mycmap', rgbin, N=N)
9090

9191
return cmap
92+
93+
94+
def lighten(cmapin, alpha):
95+
'''Lighten a colormap by adding alpha < 1.
96+
97+
:param cmap: A colormap object, like cmocean.cm.matter.
98+
:param alpha: An alpha or transparency value to assign the colormap. Alpha
99+
of 1 is opaque and of 1 is fully transparent.
100+
101+
Outputs resultant colormap object.
102+
103+
This will lighten the appearance of a plot you make using the output
104+
colormap object. It is also possible to lighten many plots in the
105+
plotting function itself (e.g. pcolormesh or contourf).
106+
'''
107+
108+
# set the alpha value while retaining the number of rows in original cmap
109+
return cmap(cmapin(np.linspace(0,1,cmapin.N), alpha))

0 commit comments

Comments
 (0)