Repository: SarthakJariwala/seaborn-image

Issue:
Can't input colormaps to imshow
Hi, i was trying to use a colormap from the sunpy library to display images of the sun with seaborn_image, but i encountered a bug where when reading the Colormap class it throws an "unhashable type" error.

Here's a piece of code to reproduce the bug:
```
import numpy as np
import matplotlib.cm as cm
import seaborn_image as isns

img = np.random.random([32,32])
isns.imshow(img, cmap=cm.get_cmap("inferno"))
```

This yeilds the following error:
```
TypeError                                 Traceback (most recent call last)
Cell In[4], line 1
----> 1 isns.imshow(img, cmap=cm.get_cmap("inferno"))

File [~/.local/lib/python3.10/site-packages/seaborn_image/_general.py:362](https://file+.vscode-resource.vscode-cdn.net/home/eugeniolr/Documents/invAI/misc/~/.local/lib/python3.10/site-packages/seaborn_image/_general.py:362), in imshow(data, **kwargs)
    359 @is_documented_by(imgplot)
    360 def imshow(data, **kwargs):
--> 362     ax = imgplot(data, **kwargs)
    364     return ax

File [~/.local/lib/python3.10/site-packages/seaborn_image/_general.py:345](https://file+.vscode-resource.vscode-cdn.net/home/eugeniolr/Documents/invAI/misc/~/.local/lib/python3.10/site-packages/seaborn_image/_general.py:345), in imgplot(data, ax, cmap, gray, vmin, vmax, alpha, origin, interpolation, norm, robust, perc, dx, units, dimension, describe, map_func, cbar, orientation, cbar_log, cbar_label, cbar_ticks, showticks, despine, **kwargs)
    320     data = map_func(data, **map_func_kwargs)
    322 img_plotter = _SetupImage(
    323     data=data,
    324     ax=ax,
   (...)
    342     despine=despine,
    343 )
--> 345 f, ax, cax = img_plotter.plot()
    347 if describe:
    348     result = ss.describe(data.flatten())

File [~/.local/lib/python3.10/site-packages/seaborn_image/_core.py:105](https://file+.vscode-resource.vscode-cdn.net/home/eugeniolr/Documents/invAI/misc/~/.local/lib/python3.10/site-packages/seaborn_image/_core.py:105), in _SetupImage.plot(self)
    102 def plot(self):
    103     f, ax = self._setup_figure()
--> 105     if self.cmap in _CMAP_QUAL.keys():
    106         self.cmap = _CMAP_QUAL.get(self.cmap).mpl_colormap
    108     if self.robust:

TypeError: unhashable type: 'ListedColormap'
```

cm.get_cmap("inferno") returns a colormap of type 'ListedColormap', if this code is executed but using matplotlib's imshow function everything works fine.

 



Discussion:
Thanks for reporting (and a piece of code to reproduce the bug)! I will create a fix today or over the weekend.

In the meantime, you can use matplotlib's colormaps directly in seaborn-image by referencing the string name instead of ListedColormap type.
This would work: 
```python
isns.imshow(img, cmap="inferno")  # will plot using matplotlib's inferno cmap
```

Resolving patch:
diff --git a/src/seaborn_image/_context.py b/src/seaborn_image/_context.py
--- a/src/seaborn_image/_context.py
+++ b/src/seaborn_image/_context.py
@@ -123,7 +123,7 @@ def set_image(cmap="deep", origin="lower", interpolation="nearest", despine=Fals
 
     """
 
-    if cmap in _CMAP_QUAL.keys():  # doesn't work currently
+    if isinstance(cmap, str) and cmap in _CMAP_QUAL.keys():
         cmap_mpl = _CMAP_QUAL.get(cmap).mpl_colormap
         try:
             register_cmap(name=cmap, cmap=cmap_mpl)
diff --git a/src/seaborn_image/_core.py b/src/seaborn_image/_core.py
--- a/src/seaborn_image/_core.py
+++ b/src/seaborn_image/_core.py
@@ -102,7 +102,7 @@ def _setup_scalebar(self, ax):
     def plot(self):
         f, ax = self._setup_figure()
 
-        if self.cmap in _CMAP_QUAL.keys():
+        if isinstance(self.cmap, str) and self.cmap in _CMAP_QUAL.keys():
             self.cmap = _CMAP_QUAL.get(self.cmap).mpl_colormap
 
         if self.robust:


Test patch:
diff --git a/tests/test_core.py b/tests/test_core.py
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -8,6 +8,7 @@
 import numpy as np
 from matplotlib.axes import Axes
 from matplotlib.figure import Figure
+from matplotlib import colormaps as mpl_colormaps
 
 import seaborn_image as isns
 
@@ -140,8 +141,8 @@ def test_data_plotted_is_same_as_input():
 
 
 @pytest.mark.parametrize(
-    "cmap", [None, "acton"]
-)  # test if seaborn-image supplied cmaps are working
+    "cmap", [None, "acton", mpl_colormaps["inferno"]]
+)  # test if seaborn-image supplied cmaps and mpl Colormaps type are working
 @pytest.mark.parametrize(
     "dx, units, dimension",
     [(None, None, None), (1, "nm", "si"), (1, "1/um", "si-reciprocal")],