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

AttributeError: 'GeoAxesSubplot' object has no attribute '_hold' #1365

Closed
jinlx opened this issue Sep 17, 2019 · 7 comments
Closed

AttributeError: 'GeoAxesSubplot' object has no attribute '_hold' #1365

jinlx opened this issue Sep 17, 2019 · 7 comments

Comments

@jinlx
Copy link

jinlx commented Sep 17, 2019

Description

Hi there,

I am trying to do a 2D plot. I get a xarray data 'co' in lat and lon dimension. I want to use co.plot(ax=ax,cmap=WhGrYlRd) to plot it.
However, I got a traceback like this

Traceback (most recent call last):
  File "panel_na.py", line 44, in <module>
    co.plot()
  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 to reproduce

# 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')

@greglucas
Copy link
Contributor

I think your title is misleading, I don't see that error in your output at all?

It doesn't look like you are doing a surface plot to me. I don't know what your dataset is, but here is a link to xarray map examples. Try following that with the contour call.
http://xarray.pydata.org/en/stable/plotting.html#maps

@jinlx
Copy link
Author

jinlx commented Sep 18, 2019

I think your title is misleading, I don't see that error in your output at all?

It doesn't look like you are doing a surface plot to me. I don't know what your dataset is, but here is a link to xarray map examples. Try following that with the contour call.
http://xarray.pydata.org/en/stable/plotting.html#maps

Sorry, I use the wrong traceback. I have updated it now. Thanks for pointing out it.

@greglucas
Copy link
Contributor

Ah, I was answering the wrong question then :) Now with the new traceback, it looks like this is the same issue as seen here:
#1120

@dopplershift
Copy link
Contributor

I agree that this looks like #1120. @jinlx what versions of cartopy and matplotlib do you have installed? Can you upgrade to more recent versions?

@jinlx
Copy link
Author

jinlx commented Sep 20, 2019

Here are the versions of my cartopy and matplotlib.
Cartopy 0.16.0
matplotlib 3.1.1
I think you are right. It is caused by old version I use.

@dopplershift
Copy link
Contributor

Well #1120 was fixed in CartoPy 0.17.0, so I'm pretty sure upgrading would solve your problem.

@jinlx
Copy link
Author

jinlx commented Sep 21, 2019

Well #1120 was fixed in CartoPy 0.17.0, so I'm pretty sure upgrading would solve your problem.

Ryan--Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants