Re: Matplotlib "collections" module in recent Python, Matplotlib
MRAB <[email protected]>
| Newsgroups | gmane.comp.python.general |
|---|---|
| Message-ID | <[email protected]> |
On 2025-06-15 04:53, jmhannon.ucdavis--- via Python-list wrote: > Greetings. We (the group that I work with) have "inherited" some Python > scripts that were written years ago, using Python 2. > > We're trying to upgrade the scripts so that they work in our current > environment: > > OS: Ubuntu 24.04.2 LTS > > $ python --version > Python 3.11.13 > > >>> matplotlib.__version__ > '3.10.0' > > > The first script that we looked at has a line: > > cs = plt.contourf(X, Y, data, LevelsNumber, > cmap=plt.cm.nipy_spectral, norm=norm).collections > > If I run that script with python 3, I get a warning: > > MatplotlibDeprecationWarning: The collections attribute was > deprecated in Matplotlib 3.8 and will be removed two minor > releases later. > cmap=plt.cm.nipy_spectral, norm=norm).collections > > I also get the following error: > > paths = cs.get_paths() > ^^^^^^^^^^^^ > AttributeError: 'list' object has no attribute 'get_paths' > > The "paths" object that I get appears to be no more than a collection of > geometric factors, i.e., without additional attributes such as color, for > instance, and statements such as the following fail: > > bgra_array = 255*paths[i].get_facecolor()[0] > > AttributeError: 'Path' object has no attribute 'get_facecolor' > > Unfortunately, all the suggestions that I've found to remedy this suggest > using the "collections" attribute, which is already in the code, and which as > I noted above, has been deprecated (maybe eliminated -- 3.10 vs. 3.8) now. > > If you have any suggestions about this, please pass 'em along. Thanks. > Does this help? https://discourse.matplotlib.org/t/collections-attribute-deprecation-in-version-3-8/24164