Skip to content

Commit 22d50cf

Browse files
committed
made a few updates and tried this out
1 parent bbaaa60 commit 22d50cf

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

cmocean/cm.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,10 @@
1212

1313
import numpy as np
1414
import os
15+
from matplotlib import colors, cm
1516

1617
from . import tools
1718

18-
# If matplotlib is available, load it
19-
try:
20-
import matplotlib.colors as mplc
21-
import matplotlib.pyplot as plt
22-
do_registry = True
23-
except:
24-
do_registry = False
25-
2619
# Location of rgb files
2720
datadir = os.path.join(os.path.split(__file__)[0], 'rgb')
2821

@@ -41,18 +34,17 @@
4134
cmap_d[cmapname].name = cmapname
4235
cmap_d[cmapname + '_r'] = tools.cmap(rgb[::-1, :], N=256)
4336
cmap_d[cmapname + '_r'].name = cmapname + '_r'
44-
45-
# Register the cmap with matplotlib, if available
46-
if do_registry:
47-
rgb_with_alpha = np.zeros((rgb.shape[0],4))
48-
rgb_with_alpha[:,:3] = rgb
49-
rgb_with_alpha[:,3] = 1. #set alpha channel to 1
50-
reg_map = mplc.ListedColormap(rgb_with_alpha, 'cmocean_' + cmapname, rgb.shape[0])
51-
plt.register_cmap(cmap = reg_map)
52-
53-
# Register the reversed map
54-
reg_map_r = mplc.ListedColormap(rgb_with_alpha[::-1,:], 'cmocean_' + cmapname + '_r', rgb.shape[0])
55-
plt.register_cmap(cmap = reg_map_r)
37+
38+
# Register the cmap with matplotlib
39+
rgb_with_alpha = np.zeros((rgb.shape[0],4))
40+
rgb_with_alpha[:,:3] = rgb
41+
rgb_with_alpha[:,3] = 1. #set alpha channel to 1
42+
reg_map = colors.ListedColormap(rgb_with_alpha, 'cmo.' + cmapname, rgb.shape[0])
43+
cm.register_cmap(cmap = reg_map)
44+
45+
# Register the reversed map
46+
reg_map_r = colors.ListedColormap(rgb_with_alpha[::-1,:], 'cmo.' + cmapname + '_r', rgb.shape[0])
47+
cm.register_cmap(cmap = reg_map_r)
5648

5749
# make colormaps available to call
5850
locals().update(cmap_d)

0 commit comments

Comments
 (0)