script to explore colormaps now also creates inverted version
@@ -17,6 +17,7 @@ https://matplotlib.org/stable/tutorials/colors/colormaps.html#lightness-of-matpl
from os.path import join
import numpy
from matplotlib.pyplot import subplots, close
+from matplotlib.colors import ListedColormap
from scipy.io import loadmat
from seaborn import color_palette
from rsatoolbox.rdm.rdms import RDMs, get_categorical_rdm
@@ -33,8 +34,10 @@ model = get_categorical_rdm([0]*5 + [1]*5 + [0]*5 + [1]*5 + [0]*20)
noise = RDMs(dissimilarities=numpy.random.rand(780))
rdm_variants = [model, noise, data]
-cm_options = [None, 'flare_r', 'crest_r',
+cm_options = [None, 'flare_r', 'crest_r', 'gray', 'bone',
'magma', 'viridis', 'plasma', 'inferno', 'cividis']
+
+for direction in ('dark2light', 'light2dark'):
fig, axes = subplots(
ncols=len(rdm_variants)+1,
nrows=len(cm_options),
@@ -44,6 +47,8 @@ for c, cmap in enumerate(cm_options):
if cmap is None:
colormap, cmap_name = rdm_colormap(), 'current'
else:
+ if direction == 'light2dark':
+ cmap = cmap[:-2] if '_r' in cmap else cmap + '_r'
colormap, cmap_name = color_palette(cmap, as_cmap=True), cmap
for r, rdm in enumerate(rdm_variants):
img = show_rdm_panel(rdm, ax=axes[c, r], cmap=colormap)
@@ -57,5 +62,5 @@ for c, cmap in enumerate(cm_options):
sample_fig.savefig(f'{cmap_name}.png', dpi=100)
fig.tight_layout()
-fig.savefig('rdm_colormaps.png', dpi=300)
+ fig.savefig(f'rdm_colormaps_{direction}.png', dpi=300)
close('all')
\ No newline at end of file
