SciTools / cartopy

Cartopy - a cartographic python library with matplotlib support
https://scitools.org.uk/cartopy/docs/latest
BSD 3-Clause "New" or "Revised" License
1.43k stars 365 forks source link

raise AttributeError(f"{type(self).__name__!r} object " AttributeError: 'QuadMesh' object has no property 'cbar' #2002

Closed haritha1022 closed 2 years ago

haritha1022 commented 2 years ago

Description

import xarray as xr import cartopy.crs as ccrs from cartopy import feature as cf import matplotlib.pyplot as plt import numpy as np import seaborn as sns

Opening and reading data

data=xr.open_dataset("uvg.nc")

print(data) def main(): x=data.longitude[::5]; y=data.latitude[::5] u=data.u[5,::5,::5]; v=data.v[5,::5,::5] z=data.z[5] ax1 = plt.subplot(3,2,1,projection=ccrs.PlateCarree()) z.plot.pcolormesh(cmap="turbo",vmin=7500,vmax=8500, ax = ax1,cbar=False) ax1.set_extent([60, 100, 38, 0]) ax1.coastlines()

ax1.quiver(x,y,u,v, angles='xy', scale_units='xy', scale=4)

x=data.longitude[::5]; 
y=data.latitude[::5]
u=data.u[6,::5,::5]; 
v=data.v[6,::5,::5]
z=data.z[6]
ax2 = plt.subplot(3,2,2,projection=ccrs.PlateCarree())
z.plot.pcolormesh(cmap="turbo",vmin=7500,vmax=8500, ax = ax2)
ax2.set_extent([60, 100, 38, 0])
ax2.coastlines()
ax2.quiver(x,y,u,v, angles='xy', scale_units='xy', scale=4)

x=data.longitude[::5]; 
y=data.latitude[::5]
u=data.u[7,::5,::5]; 
v=data.v[7,::5,::5]
z=data.z[7]
ax3 = plt.subplot(3,2,3,projection=ccrs.PlateCarree())
z.plot.pcolormesh(cmap="turbo",vmin=7500,vmax=8500, ax = ax3)
ax3.set_extent([60, 100, 38, 0])
ax3.coastlines()
ax3.quiver(x,y,u,v, angles='xy', scale_units='xy', scale=4)

x=data.longitude[::5]; 
y=data.latitude[::5]
u=data.u[8,::5,::5]; 
v=data.v[8,::5,::5]
z=data.z[8]
ax4 = plt.subplot(3,2,4,projection=ccrs.PlateCarree())
z.plot.pcolormesh(cmap="turbo",vmin=7500,vmax=8500, ax = ax4)
ax4.set_extent([60, 100, 38, 0])
ax4.coastlines()
ax4.quiver(x,y,u,v, angles='xy', scale_units='xy', scale=4)

x=data.longitude[::5]; 
y=data.latitude[::5]
u=data.u[9,::5,::5]; 
v=data.v[9,::5,::5]
z=data.z[9]
ax5 = plt.subplot(3,2,5,projection=ccrs.PlateCarree())
z.plot.pcolormesh(cmap="coolwarm")
ax5.set_extent([60, 100, 38, 0])
ax5.coastlines()
ax5.quiver(x,y,u,v, angles='xy', scale_units='xy', scale=4)

plt.savefig("winds.eps")
plt.show()

if name == "main": main()

Traceback

Full environment definition ### Operating system ### Cartopy version ### conda list ``` ``` ### pip list ``` ```
greglucas commented 2 years ago

I think you are calling the xarray plotting method incorrectly and this is not an issue with Cartopy. See here for the call signature: https://xarray.pydata.org/en/stable/generated/xarray.plot.pcolormesh.html