Repository navigation
Expand file tree
/
Copy pathGeriMap.py
More file actions
86 lines (66 loc) · 2.9 KB
/
Copy pathGeriMap.py
File metadata and controls
86 lines (66 loc) · 2.9 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import matplotlib as mpl # Importáljuk a fő modult is
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
import numpy as np
def get(reverse=False):
gm = [(0, 0, 0), (.15, .15, .5), (.3, .15, .75),
(.6, .2, .50), (1, .25, .15), (.9, .5, 0),
(.9, .75, .1), (.9, .9, .5), (1, 1, 1)]
if reverse:
return LinearSegmentedColormap.from_list('GeriMap_r', gm[::-1])
else:
return LinearSegmentedColormap.from_list('GeriMap', gm)
def registerGeriMap(transparencyThreshold=0.4):
"""
Register the perceptually uniform colormap 'GeriMap' with matplotlib
transparencyThreshold: All intensities below this threshold will have
a non-zero alpha value (making them more or
less transparent). The opacity varies linearly,
being 1 at this value, and 0 at zero.
"""
gm = [(0, 0, 0), (.15, .15, .5), (.3, .15, .75),
(.6, .2, .50), (1, .25, .15), (.9, .5, 0),
(.9, .75, .1), (.9, .9, .5), (1, 1, 1)]
gerimap = LinearSegmentedColormap.from_list('GeriMap', gm)
gerimap_r = LinearSegmentedColormap.from_list('GeriMap_r', gm[::-1])
if transparencyThreshold is not None:
n = int(gerimap.N * transparencyThreshold)
nn = gerimap.N - n
if n < 0 or nn < 0:
raise ValueError('Transparency threshold must be a value between 0 and 1.')
a = np.linspace(0, 1, n)
b = np.ones((nn,))
gmap = gerimap(np.arange(gerimap.N))
gmap[:,-1] = np.concatenate((a,b), axis=None)
gerimap = LinearSegmentedColormap.from_list('GeriMap', gmap)
gmap_r = gerimap_r(np.arange(gerimap.N))
gmap_r[:,-1] = np.concatenate((a,b), axis=None)
gerimap_r = LinearSegmentedColormap.from_list('GeriMap_r', gmap_r)
cmaps = plt.colormaps()
# AZ ÚJ MÓDSZER:
try:
# Modern verziók (Matplotlib 3.5+)
mpl.colormaps.register(cmap=gerimap)
mpl.colormaps.register(cmap=gerimap_r)
except AttributeError:
# Régi verziók (ha mégis ilyenbe futnál)
plt.register_cmap(cmap=gerimap)
plt.register_cmap(cmap=gerimap_r)
return gerimap, gerimap_r
def register():
gm = [(0, 0, 0), (.15, .15, .5), (.3, .15, .75),
(.6, .2, .50), (1, .25, .15), (.9, .5, 0),
(.9, .75, .1), (.9, .9, .5), (1, 1, 1)]
# Regular (dark-to-light)
gerimap = LinearSegmentedColormap.from_list('GeriMap', gm)
# Reversed (light-to-dark)
gerimap_r = LinearSegmentedColormap.from_list('GeriMap_r', gm[::-1])
# AZ ÚJ MÓDSZER:
try:
# Modern verziók (Matplotlib 3.5+)
mpl.colormaps.register(cmap=gerimap)
mpl.colormaps.register(cmap=gerimap_r)
except AttributeError:
# Régi verziók (ha mégis ilyenbe futnál)
plt.register_cmap(cmap=gerimap)
plt.register_cmap(cmap=gerimap_r)