property of 'QuadContourSet' object has no setter error after update matplotlib in python

168 views Asked by At

I wrote and ran a cod to plot a netcdf file. after upgrade pip and Libraries used , I got an error:property of 'QuadContourSet' object has no setter. I would be grateful if someone could help me to fix this error this is my code:

from netCDF4 import Dataset as NetCDFFile 
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
from mpl_toolkits.basemap import Basemap
import matplotlib.ticker as ticker 
from matplotlib.axis import Axis
fig = plt.figure(figsize=(10,9), constrained_layout=True ) 
plt.tight_layout(pad=0.4, w_pad=0.5, h_pad=1.0 )
ax = fig.add_subplot(111)
nc1 = NetCDFFile('C:/Users/Hadish/Desktop/project/shLa1850.nc')
lat = nc1.variables['lat'][:]
lon = nc1.variables['lon'][:]
sh = nc1.variables['shum'][:]
nc2 = NetCDFFile('C:/Users/Hadish/Desktop/project/omegaLa1500.nc')
lat = nc2.variables['lat'][:]
lon = nc2.variables['lon'][:]
omega = nc2.variables['omega'][:]*1000
map=Basemap(projection='merc',llcrnrlon=0.,llcrnrlat=10.,urcrnrlon=80.,urcrnrlat=45.
,resolution='i' ,suppress_ticks=False)  
lat_ticks=np.arange(np.ceil(15.0),int(45.0),5)
lon_ticks=np.arange(np.ceil(40.0),int(70.0),5)
lon_ticks_proj, _=map(lon_ticks, np.zeros(len(lon_ticks)))
_, lat_ticks_proj=map(np.zeros(len(lat_ticks)), lat_ticks)
ax.set_xticks(lon_ticks_proj)
ax.set_yticks(lat_ticks_proj)
plt.tick_params(labelleft=False, labelbottom=False , axis='both',which='major')
map.drawcoastlines()
map.drawstates()
map.drawcountries()
map.drawlsmask(land_color='Linen', ocean_color='#CCFFFF')
map.drawcounties() 
map.drawparallels(lat_ticks,labels=[1,0,0,0],fontsize=10 , dashes=(0,1),
fontweight='bold' ,fontstyle='oblique')
map.drawmeridians(lon_ticks,labels=[0,0,0,1],fontsize=10, dashes=(0,1) , 
fontweight='bold',  fontstyle='oblique')
lons,lats= np.meshgrid(lon-180,lat)
x,y = map(lons,lats)
clevs1 = np.arange(-6,6,1)
plt.title('SH')
cs1 = map.contourf(x,y,sh[0,:,:],clevs1,cmap='RdBu')
cb = map.colorbar(cs1,"bottom", size="4%", pad="5%")
cb.set_label('SH*10000')
clevs2 = np.arange(-10,10,2)
cs2 = map.contour(x,y,omega[0,:,:],clevs2,colors='blue',linewidths=1.)
plt.clabel(cs2, fontsize=9, inline=1) 
plt.savefig('sh-omega.png')
plt.show()

after upgrade pip and Libraries used , I got an error:property of 'QuadContourSet' object has no setter. I would be grateful if someone could help me to fix this error

1

There are 1 answers

0
molinav On

At the moment of the OP, basemap 1.3.9 had an upper pin for matplotlib set explicitly to <3.8. The issue that is reached here is caused by an interface change in matplotlib for which basemap was still not prepared.

basemap 1.4.0 has just been released today (2024-01-09) with the matplotlib pin upgraded to <3.9 and with your problem fixed:

python -m pip install "basemap >= 1.4.0"

I would like to thank @RuthC for contributing with the solution in the corresponding GitHub repo.