Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG/ISSUE] AttributeError: 'GeoAxesSubplot' object has no attribute '_hold' #6

Closed
jinlx opened this issue Sep 17, 2019 · 3 comments
Closed
Assignees
Labels
bug Something isn't working environment Related to python or conda environment

Comments

@jinlx
Copy link

jinlx commented Sep 17, 2019

Hi there,

I am trying to follow the python tutorial to get some basic plots. However, I get traceback below. Also, my code is attached below just in case.

failed to get the current screen resources
Traceback (most recent call last):
  File "panel_CO.py", line 47, in <module>
    co.plot(ax=ax,cmap=WhGrYlRd)
  File "/glade/u/home/lixujin/anaconda3/envs/geoschem/lib/python3.6/site-packages/xarray/plot/plot.py", line 552, in __call__
    return plot(self._da, **kwargs)
  File "/glade/u/home/lixujin/anaconda3/envs/geoschem/lib/python3.6/site-packages/xarray/plot/plot.py", line 187, in plot
    return plotfunc(darray, **kwargs)
  File "/glade/u/home/lixujin/anaconda3/envs/geoschem/lib/python3.6/site-packages/xarray/plot/plot.py", line 854, in newplotfunc
    **kwargs)
  File "/glade/u/home/lixujin/anaconda3/envs/geoschem/lib/python3.6/site-packages/xarray/plot/plot.py", line 1108, in pcolormesh
    primitive = ax.pcolormesh(x, y, z, **kwargs)
  File "/glade/u/home/lixujin/anaconda3/envs/geoschem/lib/python3.6/site-packages/cartopy/mpl/geoaxes.py", line 1451, in pcolormesh
    result = self._pcolormesh_patched(*args, **kwargs)
  File "/glade/u/home/lixujin/anaconda3/envs/geoschem/lib/python3.6/site-packages/cartopy/mpl/geoaxes.py", line 1469, in _pcolormesh_patched
    if not self._hold:
AttributeError: 'GeoAxesSubplot' object has no attribute '_hold'

Code

# Read data and print out to see the structure
# Pay attention to unit conversion
# Author: Lixu Jin
# Version: GEOS-CHEM 12.2.1, 09/15/2019

# import packages
#from mpl_toolkits.basemap import Basemap

from gamap_colormap import WhGrYlRd
import cartopy.crs as ccrs
import xbpch
import matplotlib.pyplot as plt
import xarray as xr    
import numpy as np
from matplotlib.colors import LogNorm

plt.style.use(['seaborn-talk', 'seaborn-ticks'])

#=============================================================
# Read single dataset
#=============================================================
# Read data
filedir = '/glade/u/home/lixujin/project/GEOS-CHEM/ExtData/HEMCO/GFAS/v2018-09/2018/'
data1 = 'GFAS_201807.nc'
data2 = 'GFAS_201808.nc'
data3 = 'GFAS_201809.nc'
ds1 = xr.open_dataset(filedir + data1)
ds2 = xr.open_dataset(filedir + data2)
ds3 = xr.open_dataset(filedir + data3)
#============================================================
# calculation part
#============================================================
# sum up druing we-can period
co = 60*60*24*1e3*(ds1['cofire'].sum('time') + ds2['cofire'].sum('time') + ds3['cofire'].sum('time'))
co.attrs['unit'] = 'ppm'
print(co)
print(type(co))

# fig setting
# empty map.
fig = plt.figure(figsize=(8,4))

# without this, it would be super wired.
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines()
ax.set_title('global CO during wecan period')

co.plot(ax=ax,cmap=WhGrYlRd)

#fig.plot(cmap='gist_stern') # The ax keyword is particularly useful for subplots. Can be omitted here.
fig.savefig('co_global1.jpg')
@yantosca
Copy link
Contributor

Thanks for writing. I googled this error and came across these links:

SciTools/cartopy#1120
http://ytukyg.blogspot.com/2019/01/cartopy-problem-with-pcolormesh.html

They suggest you might need to update your matplotlib version. The versions that I am using on my system are listed below:

------------------
platform        : Linux-3.10.0-957.12.1.el7.x86_64-x86_64-with-centos-7.6.1810-Core
python          : 3.6.9

VERSION NUMBERS FOR GCPy DEPENDENCIES
-------------------------------------

bottleneck      : 1.2.1
cartopy         : 0.17.0
cython          : 0.29.13
dask            : 2.3.0
graphviz        : 0.10.1
future          : 0.17.1
h5netcdf        : 0.6.2
h5py            : 2.8.0
h5pyd           : 0.3.3
IPython         : 7.7.0
matplotlib      : 3.1.1
netCDF4         : 1.4.2
notebook        : 6.0.0
numpy           : 1.16.4
pandas          : 0.25.1
pip             : 19.2.2
pycodestyle     : 2.4.0
pyresample      : 1.10.3
pytest          : 4.2.0
scipy           : 1.3.1
seaborn         : 0.9.0
setuptools      : 41.2.0
six             : 1.12.0
sphinx          : 2.1.2
xbpch           : 0.3.5
xarray          : 0.12.1
xesmf           : 0.2.0

@jinlx
Copy link
Author

jinlx commented Sep 20, 2019

Bob-thanks. I set up the environment again and it works. I think I found the reason why this AttributeError happens now. After setting up the gcpy environment, I also install the basemap package. And it will automatically downgrade some packages like cartopy and proj4, causing this attributerro eventually.

Lixu

@yantosca yantosca changed the title AttributeError: 'GeoAxesSubplot' object has no attribute '_hold' [BUG/ISSUE] AttributeError: 'GeoAxesSubplot' object has no attribute '_hold' Sep 20, 2019
@yantosca
Copy link
Contributor

Thanks for the reply. I'll go ahead and close this out. Glad it works!!

@yantosca yantosca self-assigned this Oct 17, 2019
@yantosca yantosca added bug Something isn't working environment Related to python or conda environment data Related to input data and removed data Related to input data labels Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working environment Related to python or conda environment
Projects
None yet
Development

No branches or pull requests

2 participants