-
-
Notifications
You must be signed in to change notification settings - Fork 401
/
reference-colormap-diverging.py
34 lines (28 loc) · 1.11 KB
/
reference-colormap-diverging.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# ----------------------------------------------------------------------------
# Title: Scientific Visualisation - Python & Matplotlib
# Author: Nicolas P. Rougier
# License: BSD
# ----------------------------------------------------------------------------
import numpy as np
import matplotlib.pyplot as plt
cmaps = ('PRGn', 'PiYG', 'RdYlGn', 'BrBG', 'RdGy', 'PuOr', 'RdBu',
'RdYlBu', 'Spectral', 'coolwarm_r', 'bwr_r', 'seismic_r')
n = len(cmaps)
fig = plt.figure(figsize=(4.25, n*.22), dpi=200)
ax = plt.subplot(1, 1, 1, frameon=False,
xlim=[0,10], xticks=[], yticks=[])
fig.subplots_adjust(top=0.99, bottom=0.01, left=0.18, right=0.99)
y, dy, pad = 0, 0.5, 0.1
ticks, labels = [], []
for cmap in cmaps[::-1]:
Z = np.linspace(0,1,512).reshape(1,512)
plt.imshow(Z, extent=[0,10,y,y+dy], cmap=plt.get_cmap(cmap))
ticks.append(y+dy/2)
labels.append(cmap)
y = y + dy + pad
ax.set_ylim(-pad,y)
ax.set_yticks(ticks)
ax.set_yticklabels(labels)
ax.tick_params(axis='y', which='both', length=0, labelsize="small")
plt.savefig("reference-colormap-diverging.pdf", dpi=600)
plt.show()