def __init__(self):
"""
Class for custom colormaps storage.
To use colormaps with `matplotlib.imshow` just call `plot.CMaps().cmap_name`.
Attributes
----------
cmap_cyan: matplotlib cmap
cyan colormap
cmap_yellow: matplotlib cmap
yellow colormap
cmap_red_green: matplotlib cmap
red-green colormap (low-green, zero-black, high-red),
especially suitable for differential images
"""
# CFP cmap
dict_cyan = {'red':(
(0.0, 0.0, 0.0),
(1.0, 0.0, 0.0)),
'blue':(
(0.0, 0.0, 0.0),
(1.0, 1.0, 1.0)),
'green':(
(0.0, 0.0, 0.0),
(1.0, 1.0, 1.0))}
self.cmap_cyan = LinearSegmentedColormap('Cyan', dict_cyan)
# YFP cmap
dict_yellow = {'red':(
(0.0, 0.0, 0.0),
(1.0, 1.0, 1.0)),
'blue':(
(0.0, 0.0, 0.0),
(1.0, 0.0, 0.0)),
'green':(
(0.0, 0.0, 0.0),
(1.0, 1.0, 1.0))}
self.cmap_yellow = LinearSegmentedColormap('Yellow', dict_yellow)
# red-green cmap creation
dict_red_green = {'red':(
(0.0, 0.0, 0.0),
(0.5, 0.0, 0.0),
(0.55, 0.3, 0.7),
(1.0, 1.0, 1.0)),
'blue':(
(0.0, 0.0, 0.0),
(1.0, 0.0, 0.0)),
'green':(
(0.0, 1.0, 1.0),
(0.45, 0.7, 0.3),
(0.5, 0.0, 0.0),
(1.0, 0.0, 0.0))}
self.cmap_red_green = LinearSegmentedColormap('RedGreen', dict_red_green)
@staticmethod
def plot_linearmap(cdict):
newcmp = LinearSegmentedColormap('testCmap', segmentdata=cdict, N=256)
rgba = newcmp(np.linspace(0, 1, 256))
fig, ax = plt.subplots(figsize=(4, 3), constrained_layout=True)
col = ['r', 'g', 'b']
for xx in [0.25, 0.5, 0.75]:
ax.axvline(xx, color='0.7', linestyle='--')
for i in range(3):
ax.plot(np.arange(256)/256, rgba[:, i], color=col[i])
ax.set_xlabel('index')
ax.set_ylabel('RGB')
plt.show()