Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spatial bias plot error with mpl 3.6 #135

Closed
zmoon opened this issue Oct 28, 2022 · 7 comments
Closed

Spatial bias plot error with mpl 3.6 #135

zmoon opened this issue Oct 28, 2022 · 7 comments
Labels
bug Something isn't working

Comments

@zmoon
Copy link
Collaborator

zmoon commented Oct 28, 2022

Got error message: unhashable type: 'ListedColormap' in spatial bias plot

Abbreviated traceback:

monet.plots.sp_scatter_bias(..., cmap=new_color_map(), ...) passes a custom ListedColormap.
In monet, this is passed through to pandas df.plot.scatter

Based on the message below, it seems pandas is expecting a cmap name if mpl >= 3.6?

│ /scratch/zmoon/mambaforge/envs/mm/lib/python3.9/site-packages/pandas/plottin │
│ g/_matplotlib/core.py:1225 in _make_plot                                     │
│                                                                              │
│   1222 │   │                                                                 │
│   1223 │   │   if self.colormap is not None:                                 │
│   1224 │   │   │   if mpl_ge_3_6_0():                                        │
│ > 1225 │   │   │   │   cmap = mpl.colormaps[self.colormap]                   │
│   1226 │   │   │   else:                                                     │
│   1227 │   │   │   │   cmap = self.plt.cm.get_cmap(self.colormap)            │
│   1228 │   │   else:
@zmoon zmoon added the bug Something isn't working label Oct 28, 2022
@zmoon
Copy link
Collaborator Author

zmoon commented Oct 28, 2022

For anyone who needs a quick fix, conda install 'matplotlib-base <3.6'. But I will work on resolving this for mpl 3.6.

@jianheACM
Copy link
Collaborator

jianheACM commented Nov 29, 2022

@zmoon @rschwant I had the same issue after updating the pkg.

Below is my quick fix:
In function new_color_map

...
    newcmap = ListedColormap(newcolors, name='OrangeBlue')
    mpl.colormaps.register(newcmap)

    return newcmap

In spatial bias plot:

...
    newcmap = 'OrangeBlue'
    try:
        mpl.colormaps[newcmap]
    except KeyError:
        new_color_map()
...

This will work for matplotlib >=3.6

@zmoon
Copy link
Collaborator Author

zmoon commented Nov 29, 2022

@jianheACM the bug in pandas was fixed in v1.5.2. What is your pandas version?

@zmoon
Copy link
Collaborator Author

zmoon commented Nov 29, 2022

Registering and using the string name seems like a good workaround though, maybe we should add this to MM anyway.

@jianheACM
Copy link
Collaborator

It's v1.5.1. But it's good to know it is fixed in v1.5.2.
I feel like we will have some similar issues in the future if we update pkg version.

@rschwant
Copy link
Collaborator

rschwant commented Dec 6, 2022

@jianheACM and @zmoon if you feel like registering the colormap like Jian did above will lead to less package versioning incompatibilities, I'm fine with updating this like Jian suggests.

@rschwant
Copy link
Collaborator

A better method for this has been merged to develop, to avoid future problems. Since this doesn't cause problems currently I am closing it.
#154

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants