Skip to content

Commit f85bfd4

Browse files
Merge pull request #285 from rsagroup/colormap-consensus
Change default colormap
2 parents 08feaf4 + 990860f commit f85bfd4

14 files changed

+373
-376
lines changed

demos/demo_bootstrap.ipynb

Lines changed: 54 additions & 49 deletions
Large diffs are not rendered by default.

demos/demo_dissimilarities.ipynb

Lines changed: 42 additions & 37 deletions
Large diffs are not rendered by default.

demos/demo_flexible_models.ipynb

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,27 @@
7272
"output_type": "stream",
7373
"text": [
7474
"Predicting with theta = [1,0], should return the first rdm, which is:\n",
75-
"[[0.20529161 0.18219921 0.14234779 0.15184744 0.21434174 0.1876438\n",
76-
" 0.23245372 0.16816806 0.11574728 0.21842971]]\n",
75+
"[[0.17948311 0.13203485 0.13632945 0.18298594 0.15166647 0.16234362\n",
76+
" 0.14637612 0.12058838 0.15784657 0.12497874]]\n",
7777
"The output of the model is:\n",
78-
"[0.20529161 0.18219921 0.14234779 0.15184744 0.21434174 0.1876438\n",
79-
" 0.23245372 0.16816806 0.11574728 0.21842971]\n",
78+
"[0.17948311 0.13203485 0.13632945 0.18298594 0.15166647 0.16234362\n",
79+
" 0.14637612 0.12058838 0.15784657 0.12497874]\n",
8080
"Which is indeed identical\n",
8181
"\n",
8282
"Predicting with theta = [0,1], should return the second rdm, which is:\n",
83-
"[[0.21021824 0.09930457 0.16356345 0.20092431 0.18402425 0.19685312\n",
84-
" 0.13494642 0.13652705 0.1714637 0.12152749]]\n",
83+
"[[0.14265908 0.17005546 0.18177815 0.1564901 0.13836761 0.17725487\n",
84+
" 0.09220979 0.24478309 0.15514355 0.20351734]]\n",
8585
"The output of the model is:\n",
86-
"[0.21021824 0.09930457 0.16356345 0.20092431 0.18402425 0.19685312\n",
87-
" 0.13494642 0.13652705 0.1714637 0.12152749]\n",
86+
"[0.14265908 0.17005546 0.18177815 0.1564901 0.13836761 0.17725487\n",
87+
" 0.09220979 0.24478309 0.15514355 0.20351734]\n",
8888
"Which is indeed identical\n",
8989
"\n",
9090
"Predicting with theta = [1,1], should return the sum of the first two rdms, which is:\n",
91-
"[[0.41550985 0.28150378 0.30591124 0.35277176 0.39836599 0.38449692\n",
92-
" 0.36740013 0.3046951 0.28721099 0.3399572 ]]\n",
91+
"[[0.32214218 0.30209031 0.3181076 0.33947604 0.29003408 0.33959849\n",
92+
" 0.23858592 0.36537148 0.31299012 0.32849607]]\n",
9393
"The output of the model is:\n",
94-
"[0.41550985 0.28150378 0.30591124 0.35277176 0.39836599 0.38449692\n",
95-
" 0.36740013 0.3046951 0.28721099 0.3399572 ]\n",
94+
"[0.32214218 0.30209031 0.3181076 0.33947604 0.29003408 0.33959849\n",
95+
" 0.23858592 0.36537148 0.31299012 0.32849607]\n",
9696
"Which is indeed identical\n"
9797
]
9898
}
@@ -136,11 +136,11 @@
136136
"squared euclidean\n",
137137
"\n",
138138
"dissimilarities[0] = \n",
139-
"[[0. 0.20529161 0.18219921 0.14234779 0.15184744]\n",
140-
" [0.20529161 0. 0.21434174 0.1876438 0.23245372]\n",
141-
" [0.18219921 0.21434174 0. 0.16816806 0.11574728]\n",
142-
" [0.14234779 0.1876438 0.16816806 0. 0.21842971]\n",
143-
" [0.15184744 0.23245372 0.11574728 0.21842971 0. ]]\n",
139+
"[[0. 0.17948311 0.13203485 0.13632945 0.18298594]\n",
140+
" [0.17948311 0. 0.15166647 0.16234362 0.14637612]\n",
141+
" [0.13203485 0.15166647 0. 0.12058838 0.15784657]\n",
142+
" [0.13632945 0.16234362 0.12058838 0. 0.12497874]\n",
143+
" [0.18298594 0.14637612 0.15784657 0.12497874 0. ]]\n",
144144
"\n",
145145
"descriptors: \n",
146146
"\n",
@@ -161,11 +161,11 @@
161161
"squared euclidean\n",
162162
"\n",
163163
"dissimilarities[0] = \n",
164-
"[[0. 0.20529161 0.18219921 0.14234779 0.15184744]\n",
165-
" [0.20529161 0. 0.21434174 0.1876438 0.23245372]\n",
166-
" [0.18219921 0.21434174 0. 0.16816806 0.11574728]\n",
167-
" [0.14234779 0.1876438 0.16816806 0. 0.21842971]\n",
168-
" [0.15184744 0.23245372 0.11574728 0.21842971 0. ]]\n",
164+
"[[0. 0.17948311 0.13203485 0.13632945 0.18298594]\n",
165+
" [0.17948311 0. 0.15166647 0.16234362 0.14637612]\n",
166+
" [0.13203485 0.15166647 0. 0.12058838 0.15784657]\n",
167+
" [0.13632945 0.16234362 0.12058838 0. 0.12497874]\n",
168+
" [0.18298594 0.14637612 0.15784657 0.12497874 0. ]]\n",
169169
"\n",
170170
"descriptors: \n",
171171
"\n",
@@ -209,9 +209,9 @@
209209
"output_type": "stream",
210210
"text": [
211211
"Theta based on optimization:\n",
212-
"[0.54167376 0.8405888 ]\n",
212+
"[0.94571213 0.32500549]\n",
213213
"Theta based on fit_regress:\n",
214-
"[0.54166958 0.8405915 ]\n"
214+
"[0.94571213 0.32500548]\n"
215215
]
216216
}
217217
],
@@ -245,10 +245,10 @@
245245
{
246246
"data": {
247247
"text/plain": [
248-
"(<Figure size 144x144 with 1 Axes>,\n",
249-
" array([[<AxesSubplot:>]], dtype=object),\n",
248+
"(<Figure size 200x200 with 1 Axes>,\n",
249+
" array([[<AxesSubplot: >]], dtype=object),\n",
250250
" defaultdict(dict,\n",
251-
" {<AxesSubplot:>: {'image': <matplotlib.image.AxesImage at 0x7fba190f22e0>}}))"
251+
" {<AxesSubplot: >: {'image': <matplotlib.image.AxesImage at 0x17f6279d0>}}))"
252252
]
253253
},
254254
"execution_count": 6,
@@ -257,19 +257,19 @@
257257
},
258258
{
259259
"data": {
260-
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAHsAAAB7CAYAAABUx/9/AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAACWklEQVR4nO3dsWoUURhH8f8Viy232C1i4ySNhWCVcp8ibCpLQWx9CG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91ua7Va1XQ6bbqrlv+2YRhqs9nU8fFxHRzsf4sdFS58aPw4I5JwiSRcIgmXSMIlknCJJFwi/Qmeoo0IvbUyEAAAAABJRU5ErkJggg==",
261261
"text/plain": [
262-
"<Figure size 144x144 with 1 Axes>"
262+
"<Figure size 200x200 with 1 Axes>"
263263
]
264264
},
265265
"metadata": {},
266266
"output_type": "display_data"
267267
},
268268
{
269269
"data": {
270-
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAHsAAAB7CAYAAABUx/9/AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAACWklEQVR4nO3dsWoUURhH8f8Viy232C1i4ySNhWCVcp8ibCpLQWx9CGvxASSNgYAh3b7FTmsppE1CIGIpXgvb3anujeA5v/bCNwOHmerb2VJrjRie/Osb0OMxNoixQYwNYmwQY4M8nTpcLBZ1GIYOlx07zEzG8aD5zNnhrPnMJDm6v+8y99vDw12tdbnrbDL2MAzZbrcdbql0mJmU8rb5zKMPL5rPTJKL8/Muc19tNtf7znyNgxgbxNggxgYxNoixQYwNYmwQY4MYG8TYIMYGMTaIsUGMDWJsEGODGBvE2CDGBplcOPy7BdpjObDPjwlvXre/11+fmo9Mknx/d9Zn8Gaz98gnG8TYIMYGMTaIsUGMDWJsEGODGBvE2CDGBjE2iLFBjA1ibBBjgxgbxNggxgYxNoixQSa3S8fxoMsnIntsgSbJ8kv7rdXy8XPzmUmSn7/7zJ3gkw1ibBBjgxgbxNggxgYxNoixQYwNYmwQY4MYG8TYIMYGMTaIsUGMDWJsEGODGBtkcuFwdjjr8v/RvT4R2WM5sL5/03xmkpxeXXWZezlx5pMNYmwQY4MYG8TYIMYGMTaIsUGMDWJsEGODGBvE2CDGBjE2iLFBjA1ibBBjgxgbxNggpdb9n4B8OZ/Xi9Wq+UV/rNfNZybJqsMnItfP5s1nJsnXk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QSLpGESyThEkm4RBIukYRLJOESSbhEEi6RLrV6sevu1tHR7eu6yz96+PTBjc/cabU18eefnjSZW1V1//4XTeaen78dfdYTl0jCJZJwiSRcIgmXSMIlknCJJFwiCZdIwiWScIkkXCIJl0jCJZJwiSRcIgmXSMIlknCJJFwiCZdIwiWScIkkXCIJl0jCJZJwiSRcIgmXSMIl0mQYhuGiQ33f13w+r/V6XbPZ7Cbu9TeTyeTGZ+5888MvTeb+8dvvTeZWVb148WuTuZfpzBOXSMIlknCJJFwiCZdIwiWScIkkXCIJl0jCJZJwiSRcIgmXSMIlknCJJFwiCZdIwiWScIkkXCIJl0jCJZJwiSRcIgmXSMIlknCJJFwiCZdIt8Yc2i107Pv+Wi/zIXrz+lWTuefnb5vMrWr3Pe/mjlggOm7N6NnZWXVd9/43gxGWy2UtFou9Z0aFu91ua7Va1XQ6bbqrlv+2YRhqs9nU8fFxHRzsf4sdFS58aPw4I5JwiSRcIgmXSMIlknCJJFwi/Qmeoo0IvbUyEAAAAABJRU5ErkJggg==",
271271
"text/plain": [
272-
"<Figure size 144x144 with 1 Axes>"
272+
"<Figure size 200x200 with 1 Axes>"
273273
]
274274
},
275275
"metadata": {},
@@ -301,9 +301,9 @@
301301
"name": "stdout",
302302
"output_type": "stream",
303303
"text": [
304-
"[0.54171328 0.84056334]\n",
304+
"[0.94571213 0.32500549]\n",
305305
"the used fitting function was:\n",
306-
"<function fit_optimize at 0x7fba18bdb9d0>\n"
306+
"<function fit_optimize at 0x153191000>\n"
307307
]
308308
}
309309
],
@@ -338,9 +338,9 @@
338338
"name": "stdout",
339339
"output_type": "stream",
340340
"text": [
341-
"[-0.04123096 0.99914964]\n",
342-
"[-0.04123086 0.99914965]\n",
343-
"[-0.04122998 0.99914968]\n"
341+
"[ 0.996767 -0.08034645]\n",
342+
"[ 0.996767 -0.08034645]\n",
343+
"[ 0.996767 -0.08034647]\n"
344344
]
345345
}
346346
],
@@ -378,13 +378,13 @@
378378
"output_type": "stream",
379379
"text": [
380380
"The average correlation for the correlation parameters is:\n",
381-
"0.20919570220266936\n",
381+
"0.0890392385172882\n",
382382
"The average correlation for the cosine similarity parameters is:\n",
383-
"0.1648685520549055\n",
383+
"0.06085602619789239\n",
384384
"The average cosine similarity for the correlation parameters is:\n",
385-
"0.9609090694876308\n",
385+
"0.9649654254976477\n",
386386
"The average cosine similarity for the cosine similarity parameters is:\n",
387-
"0.9712386973494105\n"
387+
"0.9721299166013238\n"
388388
]
389389
}
390390
],
@@ -432,7 +432,7 @@
432432
],
433433
"metadata": {
434434
"kernelspec": {
435-
"display_name": "Python 3",
435+
"display_name": "env",
436436
"language": "python",
437437
"name": "python3"
438438
},
@@ -446,7 +446,12 @@
446446
"name": "python",
447447
"nbconvert_exporter": "python",
448448
"pygments_lexer": "ipython3",
449-
"version": "3.8.8"
449+
"version": "3.10.4"
450+
},
451+
"vscode": {
452+
"interpreter": {
453+
"hash": "af6f0c1be22da210ce14b764d3d407b4e31df46360687c396ac7d1fbf0a9a76f"
454+
}
450455
}
451456
},
452457
"nbformat": 4,

demos/demo_rdm_comparison_scatterplot.ipynb

Lines changed: 11 additions & 6 deletions
Large diffs are not rendered by default.

demos/demo_rdm_visualisation_92images.ipynb

Lines changed: 95 additions & 131 deletions
Large diffs are not rendered by default.

demos/demo_temporal.ipynb

Lines changed: 78 additions & 77 deletions
Large diffs are not rendered by default.

demos/temp_rdm.png

1.39 MB
Loading

src/rsatoolbox/util/vis_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ class Weighted_MDS(BaseEstimator):
422422

423423
def __init__(self, n_components=2, *, metric=True, n_init=4,
424424
max_iter=300, verbose=0, eps=1e-3, n_jobs=None,
425-
random_state=None, dissimilarity="euclidean"):
425+
random_state=None, dissimilarity="euclidean",
426+
normalized_stress='auto'):
426427
self.n_components = n_components
427428
self.dissimilarity = dissimilarity
428429
self.metric = metric
@@ -436,6 +437,8 @@ def __init__(self, n_components=2, *, metric=True, n_init=4,
436437
self.embedding_ = None
437438
self.stress_ = None
438439
self.n_iter_ = None
440+
# not in use, declared for consistency with sklearn:
441+
self.normalized_stress = normalized_stress
439442

440443
@property
441444
def _pairwise(self):

src/rsatoolbox/vis/colors.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
#!/usr/bin/python
2-
# -*- coding: UTF-8 -*-
31
"""
4-
Definition of rsatoolbox's colors
2+
Classic colormap ported from matlab rsatoolbox
53
64
@author: iancharest
75
"""
8-
6+
from __future__ import annotations
97
import numpy as np
108
from skimage.color import rgb2hsv, hsv2rgb
119
import matplotlib.pyplot as plt
1210
from matplotlib.colors import ListedColormap
1311
from scipy.interpolate import interp1d
1412

1513

16-
def color_scale(n_cols, anchor_cols=None, monitor=False):
14+
def color_scale(n_cols: int, anchor_cols=None, monitor=False):
1715
""" linearly interpolates between a set of given
1816
anchor colours to give n_cols and displays them
1917
if monitor is set
@@ -55,7 +53,7 @@ def color_scale(n_cols, anchor_cols=None, monitor=False):
5553
return cols
5654

5755

58-
def rdm_colormap(n_cols=256, monitor=None):
56+
def rdm_colormap_classic(n_cols: int = 256, monitor: bool = False):
5957
"""this function provides a convenient colormap for visualizing
6058
dissimilarity matrices. it goes from blue to yellow and has grey for
6159
intermediate values.
@@ -73,8 +71,8 @@ def rdm_colormap(n_cols=256, monitor=None):
7371
7472
import numpy as np
7573
import matplotlib.pyplot as plt
76-
from rsatoolbox.vis.colors import rdm_colormap
77-
plt.imshow(np.random.rand(10,10),cmap=rdm_colormap())
74+
from rsatoolbox.vis.colors import rdm_colormap_classic
75+
plt.imshow(np.random.rand(10,10),cmap=rdm_colormap_classic())
7876
plt.colorbar()
7977
plt.show()
8078

src/rsatoolbox/vis/icon.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import os
88
import matplotlib.pyplot as plt
9-
from matplotlib import cm
9+
import matplotlib
1010
from matplotlib.offsetbox import OffsetImage, AnnotationBbox, DrawingArea
1111
import numpy as np
1212
import PIL
@@ -15,6 +15,10 @@
1515
from PIL import UnidentifiedImageError
1616
from rsatoolbox.rdm import RDMs
1717
from rsatoolbox.util.pooling import pool_rdm
18+
if hasattr(matplotlib.colormaps, 'get_cmap'):
19+
mpl_get_cmap = matplotlib.colormaps.get_cmap
20+
else:
21+
mpl_get_cmap = matplotlib.cm.get_cmap # drop:py37
1822

1923

2024
class Icon:
@@ -243,7 +247,7 @@ def recompute_final_image(self):
243247
else:
244248
im = self._image
245249
if self.cmap is not None:
246-
im = cm.get_cmap(self.cmap)(im)
250+
im = mpl_get_cmap(self.cmap)(im)
247251
im = PIL.Image.fromarray((im * 255).astype(np.uint8))
248252
else: # we hope it is a PIL image or equivalent
249253
im = self._image

src/rsatoolbox/vis/rdm_plot.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,27 @@
66

77
from __future__ import annotations
88
import collections
9-
from typing import TYPE_CHECKING, Union, Tuple
9+
from typing import TYPE_CHECKING, Union, Tuple, Optional
1010
import pkg_resources
1111
import numpy as np
1212
import matplotlib
1313
import matplotlib.pyplot as plt
1414
import rsatoolbox.rdm
1515
from rsatoolbox import vis
16-
from rsatoolbox.vis.colors import rdm_colormap
16+
from rsatoolbox.vis.colors import rdm_colormap_classic
1717
if TYPE_CHECKING:
1818
import numpy.typing as npt
1919
import pathlib
2020
from matplotlib.axes._axes import Axes
21+
from matplotlib.colors import Colormap
2122

2223
RDM_STYLE = pkg_resources.resource_filename('rsatoolbox.vis', 'rdm.mplstyle')
2324

2425

2526
def show_rdm(
2627
rdm: rsatoolbox.rdm.RDMs,
2728
pattern_descriptor: str = None,
28-
cmap: Union[str, matplotlib.colors.Colormap] = None,
29+
cmap: Union[str, Colormap] = 'bone',
2930
rdm_descriptor: str = None,
3031
n_column: int = None,
3132
n_row: int = None,
@@ -48,8 +49,10 @@ def show_rdm(
4849
rdm (rsatoolbox.rdm.RDMs): RDMs object to be plotted.
4950
pattern_descriptor (str): Key into rdm.pattern_descriptors to use for axis
5051
labels.
51-
cmap (Union[str, matplotlib.colors.Colormap]): colormap to be used (by
52-
plt.imshow internally). By default we use rdm_colormap.
52+
cmap (str or Colormap): Colormap to be used.
53+
Either the name of a Matplotlib built-in colormap, a Matplotlib
54+
Colormap compatible object, or 'classic' for the matlab toolbox
55+
colormap. Defaults to 'bone'.
5356
rdm_descriptor (str): Key for rdm_descriptor to use as panel title, or
5457
str for direct labeling.
5558
n_column (int): Number of columns in subplot arrangement.
@@ -255,8 +258,8 @@ def _rdm_colorbar(
255258

256259
def show_rdm_panel(
257260
rdm: rsatoolbox.rdm.RDMs,
258-
ax: Axes = None,
259-
cmap: Union[str, matplotlib.colors.Colormap] = None,
261+
ax: Optional[Axes] = None,
262+
cmap: Union[str, Colormap] = 'bone',
260263
nanmask: npt.ArrayLike = None,
261264
rdm_descriptor: str = None,
262265
gridlines: npt.ArrayLike = None,
@@ -268,8 +271,10 @@ def show_rdm_panel(
268271
Args:
269272
rdm (rsatoolbox.rdm.RDMs): RDMs object to be plotted (n_rdm must be 1).
270273
ax (matplotlib.axes._axes.Axes): Matplotlib axis handle. plt.gca() by default.
271-
cmap (Union[str, matplotlib.colors.Colormap]): colormap to be used (by
272-
plt.imshow internally). By default we use rdm_colormap.
274+
cmap (str or Colormap): Colormap to be used.
275+
Either the name of a Matplotlib built-in colormap, a Matplotlib
276+
Colormap compatible object, or 'classic' for the matlab toolbox
277+
colormap. Defaults to 'bone'.
273278
nanmask (npt.ArrayLike): boolean mask defining RDM elements to suppress
274279
(by default, the diagonals).
275280
rdm_descriptor (str): Key for rdm_descriptor to use as panel title, or
@@ -287,8 +292,8 @@ def show_rdm_panel(
287292
raise ValueError("expected single rdm - use show_rdm for multi-panel figures")
288293
if ax is None:
289294
ax = plt.gca()
290-
if cmap is None:
291-
cmap = rdm_colormap()
295+
if cmap == 'classic':
296+
cmap = rdm_colormap_classic()
292297
if nanmask is None:
293298
nanmask = np.eye(rdm.n_cond, dtype=bool)
294299
if not np.any(gridlines):

src/rsatoolbox/vis/scatter_plot.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ def show_2d(
102102
"""
103103
if method == 'MDS':
104104
MDS = sklearn.manifold.MDS if weights is None else Weighted_MDS
105-
embedding = MDS(n_components=2, random_state=seed, dissimilarity='precomputed')
105+
embedding = MDS(
106+
n_components=2,
107+
random_state=seed,
108+
dissimilarity='precomputed',
109+
# normalized_stress='auto' # drop:py37
110+
)
106111
elif method == 't-SNE':
107112
embedding = sklearn.manifold.TSNE(n_components=2)
108113
elif method == 'Isomap':

0 commit comments

Comments
 (0)