Skip to content

Commit f495e82

Browse files
committed
fixed up plot scripts
1 parent 4d4b793 commit f495e82

File tree

1 file changed

+20
-46
lines changed

1 file changed

+20
-46
lines changed

cmocean/plots.py

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,6 @@
99
import matplotlib as mpl
1010

1111
from . import cm
12-
from . import tools
13-
14-
15-
mpl.rcParams.update({'font.size': 14})
16-
mpl.rcParams['font.sans-serif'] = 'Arev Sans, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Helvetica, Avant Garde, sans-serif'
17-
mpl.rcParams['mathtext.fontset'] = 'custom'
18-
mpl.rcParams['mathtext.cal'] = 'cursive'
19-
mpl.rcParams['mathtext.rm'] = 'sans'
20-
mpl.rcParams['mathtext.tt'] = 'monospace'
21-
mpl.rcParams['mathtext.it'] = 'sans:italic'
22-
mpl.rcParams['mathtext.bf'] = 'sans:bold'
23-
mpl.rcParams['mathtext.sf'] = 'sans'
24-
mpl.rcParams['mathtext.fallback_to_cm'] = 'True'
25-
26-
# import pdb; pdb.set_trace()
27-
# # list of colormaps for several functions
28-
# cmaps = [cmocean.temp, cmocean.o2, cmocean.salinity, cmocean.chl,
29-
# cmocean.rho, cmocean.par, cmocean.turb, cmocean.cdom]
30-
# cmocean.bathy, cmocean.s, cmocean.v, cmocean.vort,
31-
# cmocean.eta]
32-
33-
cmaps = cm.cmap_d
3412

3513

3614
def plot_lightness(saveplot=False):
@@ -46,17 +24,19 @@ def plot_lightness(saveplot=False):
4624

4725
fig = plt.figure(figsize=(16, 6))
4826
ax = fig.add_subplot(111)
49-
ax.set_xlim(-0.1, len(cmaps) + 0.1)
27+
ax.set_xlim(-0.1, len(cm.cmap_d)/2. + 0.1)
5028
ax.set_ylim(0, 100)
51-
ax.set_xlabel('Lightness for each colormap')
29+
ax.set_xlabel('Lightness for each colormap', fontsize=14)
30+
31+
for j, cmapname in enumerate(cm.cmapnames):
5232

53-
for j, cmap in enumerate(cmaps):
33+
if '_r' in cmapname: # skip reversed versions for plot
34+
continue
35+
36+
cmap = cm.cmap_d[cmapname] # get the colormap instance
5437
rgb = cmap(x)[np.newaxis, :, :3]
5538
lab = cspace_converter("sRGB1", "CAM02-UCS")(rgb)
56-
# lab = color.rgb2lab(rgb)
5739
L = lab[0, :, 0]
58-
# import pdb; pdb.set_trace()
59-
# L = lab[0, :, 0]
6040
if L[-1] > L[0]:
6141
ax.scatter(x+j*dc, L, c=x, cmap=cmap, s=300, linewidths=0.)
6242
else:
@@ -67,7 +47,7 @@ def plot_lightness(saveplot=False):
6747
ax.xaxis.set_ticks_position('top')
6848
ticker = mpl.ticker.FixedLocator(locs)
6949
ax.xaxis.set_major_locator(ticker)
70-
formatter = mpl.ticker.FixedFormatter([cmap.name for cmap in cmaps])
50+
formatter = mpl.ticker.FixedFormatter([cmapname for cmapname in cm.cmapnames])
7151
ax.xaxis.set_major_formatter(formatter)
7252
labels = ax.get_xticklabels()
7353
for label in labels:
@@ -90,29 +70,25 @@ def plot_gallery(saveplot=False):
9070

9171
from colorspacious import cspace_converter
9272

93-
# don't have reverse colormaps built in yet
94-
rgb = tools.print_colormaps([cm.gray], returnrgb=True)
95-
gcmap = tools.cmap(rgb[::-1, :])
96-
9773
gradient = np.linspace(0, 1, 256)
9874
gradient = np.vstack((gradient, gradient))
9975
x = np.linspace(0.0, 1.0, 256)
10076

101-
fig, axes = plt.subplots(nrows=len(cmaps), ncols=1, figsize=(6, 12))
77+
fig, axes = plt.subplots(nrows=len(cm.cmap_d)/2, ncols=1, figsize=(6, 12))
10278
fig.subplots_adjust(top=0.99, bottom=0.01, left=0.2, right=0.99, wspace=0.05)
103-
# fig.suptitle('Oceanography colormaps', fontsize=16, y=1.0, x=0.6)
10479

105-
for ax, cmap in zip(axes, cmaps):
80+
for ax, cmapname in zip(axes, cm.cmapnames):
81+
82+
if '_r' in cmapname: # skip reversed versions for plot
83+
continue
84+
85+
cmap = cm.cmap_d[cmapname] # get the colormap instance
10686

10787
rgb = cmap(x)[np.newaxis, :, :3]
10888

10989
# Find a good conversion to grayscale
11090
jch = cspace_converter("sRGB1", "CAM02-UCS")(rgb) # Not sure why to use JCh instead so using this.
111-
# jch = cspace_converter("sRGB1", "JCh")(rgb)
11291
L = jch[0, :, 0]
113-
# # Get colormap in CIE LAB. We want the L here.
114-
# lab = color.rgb2lab(rgb)
115-
# L = lab[0, :, 0]
11692
L = np.float32(np.vstack((L, L, L)))
11793

11894
ax.imshow(gradient, aspect='auto', cmap=cmap)
@@ -121,7 +97,7 @@ def plot_gallery(saveplot=False):
12197
pos2 = [pos1.x0, pos1.y0, pos1.width, pos1.height / 3.0]
12298
axbw = fig.add_axes(pos2) # colorbar axes
12399
axbw.set_axis_off()
124-
axbw.imshow(L, aspect='auto', cmap=gcmap, vmin=0, vmax=100.)
100+
axbw.imshow(L, aspect='auto', cmap=cm.gray, vmin=0, vmax=100.)
125101
pos = list(ax.get_position().bounds)
126102
x_text = pos[0] - 0.01
127103
y_text = pos[1] + pos[3]/2.
@@ -173,16 +149,14 @@ def test(cmap, fig=None, ax=None):
173149

174150
# will plot colormap and lightness
175151
rgb = cmap(x)[np.newaxis, :, :3]
176-
# rgb = cm.get_cmap(cmap)(x)[np.newaxis,:,:3]
177152
lab = cspace_converter("sRGB1", "CAM02-UCS")(rgb)
178-
# lab = color.rgb2lab(rgb)
179153

180154
if ax is None:
181155
fig = plt.figure()
182156
ax = fig.add_subplot(111)
183157
ax.scatter(x, lab[0, :, 0], c=x, cmap=cmap, s=300, linewidths=0.)
184-
ax.set_title(cmap.name)
185-
ax.set_ylabel('Lightness')
158+
ax.set_title(cmap.name, fontsize=14)
159+
ax.set_ylabel('Lightness', fontsize=14)
186160
ax.set_xticks([])
187161

188162

@@ -198,7 +172,7 @@ def quick_plot(cmap, fname=None, fig=None, ax=None, N=10):
198172
fig = plt.figure()
199173
ax = fig.add_subplot(111)
200174
mappable = ax.pcolor(X, cmap=cmap)
201-
ax.set_title(cmap.name)
175+
ax.set_title(cmap.name, fontsize=14)
202176
ax.set_xticks([])
203177
ax.set_yticks([])
204178
plt.colorbar(mappable)

0 commit comments

Comments
 (0)