matplotlib / basemap

Plot on map projections (with coastlines and political boundaries) using matplotlib
MIT License
779 stars 392 forks source link

AttributeError: can't set attribute #594

Closed qianwu2 closed 10 months ago

qianwu2 commented 1 year ago

Hi, I am running basemap version 1.3.4 Matplotlib 3.8 CentOS 7.8 Using conda. Python 3.10.2 I got this error.

cs = m.contourf(x,y,pot,levels=clevs, alpha=1,cmap=plt.cm.RdBu_r) Traceback (most recent call last): File "/glade/u/home/qwu/gtrSep20/tiegcmnmf22020duskmewmeridicon092420200506sep2120202324paperafreviewmgladepy310.py", line 500, in cs = m.contourf(x,y,pot,levels=clevs, alpha=1,cmap=plt.cm.RdBu_r) File "/glade/work/qwu/conda-envs/qwu-env0/lib/python3.10/site-packages/mpl_toolkits/basemap/init.py", line 548, in with_transform return plotfunc(self,x,y,data,*args,**kwargs) File "/glade/work/qwu/conda-envs/qwu-env0/lib/python3.10/site-packages/mpl_toolkits/basemap/init.py", line 3704, in contourf CS.collections,c = self._cliplimb(ax,CS.collections) File "/glade/work/qwu/conda-envs/qwu-env0/lib/python3.10/site-packages/matplotlib/_api/deprecation.py", line 164, in set return super().set(instance, value) AttributeError: can't set attribute

molinav commented 11 months ago

Hi, @qianwu2! Right now, the requirements file defines matplotlib >= 1.5, < 3.8; python_version >= "3.5", so matplotlib 3.8 falls outside the version range that is being tested.

In any case, I thank you for providing this feedback, because soon I will need to increase the upper pin for matplotlib to 3.9. I have not done it yet because I know that matplotlib 3.8 is bringing some changes that will break with basemap right now, so it is not only a matter of updating the requirements file.

rcomer commented 11 months ago

I just tried the first (contour) and last (nightshade) examples from the docs with Matplotlib v3.8. The same line in those methods,

CS.collections,c = self._cliplimb(ax,CS.collections)

falls over for me with AttributeError: property of 'QuadContourSet' object has no setter consistent with this stackoverflow question. Since the ContourSet is now itself a collection, I suspect you just need to pass CS itself to your _cliplimb method.

molinav commented 10 months ago

@rcomer Thanks a lot for pointing to the specific issue. I will try to address it as soon as possible, because the basemap release 1.4.0 should arrive soon, and updating the matplotlib pin to <3.9 is a must in my todo list for 1.4.0.

molinav commented 10 months ago

The fix proposed by @rcomer has been added to all the affected methods (contour, contourf and nightshade), and I have also added some simple tests to the test suite to ensure that now it is working.

Thanks for your help! I will close the issue now, you will be able to use matplotlib 3.8.x with the basemap release 1.4.0, which should take place in one or two days at maximum.

qianwu2 commented 10 months ago

Many thanks for your help. Best, Qian

On Sun, Jan 7, 2024 at 1:59 PM Víctor Molina García < @.***> wrote:

Closed #594 https://github.com/matplotlib/basemap/issues/594 as completed.

— Reply to this email directly, view it on GitHub https://github.com/matplotlib/basemap/issues/594#event-11411970339, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIBNSTHCRQZFQRHSREMLJ53YNMEDLAVCNFSM6AAAAAA7IRDH72VHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJRGQYTCOJXGAZTGOI . You are receiving this because you were mentioned.Message ID: @.***>

-- Qian Wu High Altitude Observatory National Center for Atmospheric Research P.O.Box 3000 Boulder, Co 80307-3000 (303) 497 2176 (303) 497 2180