proplot-dev / proplot

🎨 A succinct matplotlib wrapper for making beautiful, publication-quality graphics
https://proplot.readthedocs.io
MIT License
1.12k stars 102 forks source link

Proplot not compatible with matplotlib 3.6 #390

Open swamidass opened 2 years ago

swamidass commented 2 years ago

Looks like the current version of proplot does not work with matplotlib==3.6 (though it works fine with 3.5).

The import:

import proplot as pplt

Throws:

AttributeError: module 'matplotlib.cm' has no attribute 'cmap_d'

From: proplot/colors.py:3111,

_cmap_database = _init_cmap_database()

This might be fixable by changing the reference to cmap_d to point instead to matplotlib.colormaps.

zxdawn commented 2 years ago

Could you try the newest version of proplot?

pip install git+https://github.com/proplot-dev/proplot.git
cvanelteren commented 2 years ago

@zxdawn works for me

swamidass commented 2 years ago

That worked. Perhaps push a release to pypi?

ForceBru commented 2 years ago

Could you try the newest version of proplot?

pip install git+https://github.com/proplot-dev/proplot.git

This downgraded Matplotlib from 3.6.1 to 3.5.3 for me...

knaaptime commented 2 years ago

Could you try the newest version of proplot?

pip install git+https://github.com/proplot-dev/proplot.git

This downgraded Matplotlib from 3.6.1 to 3.5.3 for me...

same. Looking closer, the requirements.txt file only lists matplotlib>3.0, but this line still enforces <3.6

knaaptime commented 2 years ago

(if i try to use proplot anyway in an environment with mpl 3.6.2 i get AttributeError: module 'matplotlib.cm' has no attribute 'cmap_d' )

zxdawn commented 2 years ago

@knaaptime Yes, that's caused by https://github.com/matplotlib/matplotlib/pull/22298.

knaaptime commented 2 years ago

yup, just wanted to make sure you're aware since you asked for beta testers of the current dev install :)

Z2h-A6n commented 1 year ago

I've started working on this in a fork: https://github.com/Z2h-A6n/proplot

I've (partially?) fixed the cmap_d deprecation and removal using the suggestion to use matplotlib.colormaps instead, but there's a probably-related issue that I haven't figured out how to solve, namely certain types of plots (I've tried ax.plot() which doesn't have this problem and ax.fill_between() which does) raise the following exception:

Traceback (most recent call last):
  File "fillbetween-example.py", line 4, in <module>
    ax.fill_between([0, 1], [0, 0], [1, 1])
  File "/usr/lib/python3.10/site-packages/proplot/internals/inputs.py", line 292, in _preprocess_or_redirect
    return func(self, *args, **kwargs)  # call unbound method
  File "/usr/lib/python3.10/site-packages/proplot/axes/plot.py", line 3337, in fill_between
    return self._apply_fill(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/proplot/axes/plot.py", line 3297, in _apply_fill
    obj = self._call_native(name, x, y1, y2, where=w, **kw)
  File "/usr/lib/python3.10/site-packages/proplot/axes/plot.py", line 1293, in _call_native
    obj = getattr(super(), name)(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/matplotlib/__init__.py", line 1423, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "/usr/lib/python3.10/site-packages/matplotlib/axes/_axes.py", line 5367, in fill_between
    return self._fill_between_x_or_y(
  File "/usr/lib/python3.10/site-packages/matplotlib/axes/_axes.py", line 5353, in _fill_between_x_or_y
    collection = mcoll.PolyCollection(polys, **kwargs)
  File "/usr/lib/python3.10/site-packages/matplotlib/_api/deprecation.py", line 454, in wrapper
    return func(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/matplotlib/collections.py", line 1174, in __init__
    super().__init__(**kwargs)
  File "/usr/lib/python3.10/site-packages/matplotlib/_api/deprecation.py", line 454, in wrapper
    return func(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/matplotlib/collections.py", line 158, in __init__
    cm.ScalarMappable.__init__(self, norm, cmap)
  File "/usr/lib/python3.10/site-packages/matplotlib/cm.py", line 415, in __init__
    self.set_cmap(cmap)  # The Colormap instance of this ScalarMappable.
  File "/usr/lib/python3.10/site-packages/matplotlib/cm.py", line 603, in set_cmap
    self.cmap = _ensure_cmap(cmap)
  File "/usr/lib/python3.10/site-packages/matplotlib/cm.py", line 741, in _ensure_cmap
    _api.check_in_list(sorted(_colormaps), cmap=cmap_name)
  File "/usr/lib/python3.10/site-packages/matplotlib/_api/__init__.py", line 131, in check_in_list
    raise ValueError(msg)
ValueError: 'Fire' is not a valid value for cmap; supported values are 'Accent', 'Accent_r', 'Blues', 'Blues_r', 'BrBG', 'BrBG_r', 'BuGn', 'BuGn_r', 'BuPu', 'BuPu_r', 'CMRmap', 'CMRmap_r', 'Dark2', 'Dark2_r', 'GnBu', 'GnBu_r', 'Greens', 'Greens_r', 'Greys', 'Greys_r', 'OrRd', 'OrRd_r', 'Oranges', 'Oranges_r', 'PRGn', 'PRGn_r', 'Paired', 'Paired_r', 'Pastel1', 'Pastel1_r', 'Pastel2', 'Pastel2_r', 'PiYG', 'PiYG_r', 'PuBu', 'PuBuGn', 'PuBuGn_r', 'PuBu_r', 'PuOr', 'PuOr_r', 'PuRd', 'PuRd_r', 'Purples', 'Purples_r', 'RdBu', 'RdBu_r', 'RdGy', 'RdGy_r', 'RdPu', 'RdPu_r', 'RdYlBu', 'RdYlBu_r', 'RdYlGn', 'RdYlGn_r', 'Reds', 'Reds_r', 'Set1', 'Set1_r', 'Set2', 'Set2_r', 'Set3', 'Set3_r', 'Spectral', 'Spectral_r', 'Wistia', 'Wistia_r', 'YlGn', 'YlGnBu', 'YlGnBu_r', 'YlGn_r', 'YlOrBr', 'YlOrBr_r', 'YlOrRd', 'YlOrRd_r', 'afmhot', 'afmhot_r', 'autumn', 'autumn_r', 'binary', 'binary_r', 'bone', 'bone_r', 'brg', 'brg_r', 'bwr', 'bwr_r', 'cividis', 'cividis_r', 'cool', 'cool_r', 'coolwarm', 'coolwarm_r', 'copper', 'copper_r', 'cubehelix', 'cubehelix_r', 'flag', 'flag_r', 'gist_earth', 'gist_earth_r', 'gist_gray', 'gist_gray_r', 'gist_heat', 'gist_heat_r', 'gist_ncar', 'gist_ncar_r', 'gist_rainbow', 'gist_rainbow_r', 'gist_stern', 'gist_stern_r', 'gist_yarg', 'gist_yarg_r', 'gnuplot', 'gnuplot2', 'gnuplot2_r', 'gnuplot_r', 'gray', 'gray_r', 'hot', 'hot_r', 'hsv', 'hsv_r', 'inferno', 'inferno_r', 'jet', 'jet_r', 'magma', 'magma_r', 'nipy_spectral', 'nipy_spectral_r', 'ocean', 'ocean_r', 'pink', 'pink_r', 'plasma', 'plasma_r', 'prism', 'prism_r', 'rainbow', 'rainbow_r', 'seismic', 'seismic_r', 'spring', 'spring_r', 'summer', 'summer_r', 'tab10', 'tab10_r', 'tab20', 'tab20_r', 'tab20b', 'tab20b_r', 'tab20c', 'tab20c_r', 'terrain', 'terrain_r', 'turbo', 'turbo_r', 'twilight', 'twilight_r', 'twilight_shifted', 'twilight_shifted_r', 'viridis', 'viridis_r', 'winter', 'winter_r'
dforero0896 commented 1 year ago

Hi, will there be a permanent solution to this? Some time ago using the dev version seemed to work (still raising some deprecation warnings every time the code is run) but now it just doesn't work. I've tried reinstalling proplot and proplot-dev but still get the same error. I've had to remove the proplot dependency from many scripts now but I would rather not have to since it makes plotting so much easier.

Thanks in advance for any help/info.

cvanelteren commented 1 year ago

@dforero0896 I took a stab at it in #433. Plotting seems to work again. There are no proper unittests however so I can't be sure the entire codebase works with mpl v3.8. Give it a shot if you want!

image

dforero0896 commented 1 year ago

Hi, thanks for you comment. I've tried !pip install git+https://github.com/cvanelteren/proplot.git --user but I keep getting the same error. It seems the requirement is still mpl < 3.6.0 so it downgrades.

cvanelteren commented 1 year ago

@dforero0896 You need to pull from the changed branched. The command you outlined pulls from the main branch that does not have the changes. Run:

!pip install git+https://github.com/cvanelteren/proplot.git@mpl3.8 --user from jupyter or without the ! from a terminal. Note that this does not upgrade matplotlib automatically as the code should be backwards compatible, but atleast I won't pull your mpl version down. You can upgrade mpl either before or after.

dforero0896 commented 1 year ago

Right! I didn't notice. Thanks! I just tested it and it works like a charm so far. I'll update if I find something.