plt.gca().coastlines() error

1,144 views
Skip to first unread message

Stephanie Blake

unread,
May 16, 2017, 9:09:29 PM5/16/17
to Iris
Hi again everyone, 

I am having a bit of trouble getting coastlines onto my plots in iris. This is my script:

import iris

import matplotlib.pyplot as plt

import iris.plot as iplt

import iris.quickplot as qplt

iris.FUTURE.netcdf_promote=True



filename= '~/OEH_DAY_1990-2009_ffdi.nc'

file=iris.load_cube(filename)


plot_line = file.collapsed('time', iris.analysis.MEAN)

print plot_line


plt.figure()

contour = qplt.contourf(plot_line,80)

plt.gca().coastlines()

plt.title('1990-2009 FFDI mean over time')

plt.show()



And this is the error I'm getting: 


AttributeError: 'AxesSubplot' object has no attribute 'coastlines'


I do not get this error for the plt.title. Does anyone know what is going wrong here? 


Thanks,


Steph

Ben Silver

unread,
Aug 9, 2018, 10:38:18 AM8/9/18
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
Hi Steph,

Did you manage to solve this problem? The same things is happening to me

Many thanks,
Ben

Phil Elson

unread,
Aug 9, 2018, 11:05:12 AM8/9/18
to Ben Silver, SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
This error occurs when Iris doesn't create a cartopy geoaxes for you. The reason for this will be that either you aren't plotting spatial coordinates.
Iris determines mappable coordinates at https://github.com/SciTools/iris/blob/v2.1.0/lib/iris/plot.py#L204-L212. Essentially, you need coordinates of name "latitude" & "longitude", "grid_latitude" & "grid_longitude", etc..
Simply renaming your coordinates should do the trick (coord.rename('longitude')).

Alternatively, you could construct the GeoAxes yourself if you know the coordinate system. For lats/lons, you could just do plt.axes(projection=ccrs.PlateCarree()).

Hope that makes sense, and good luck!

Phil

--
You received this message because you are subscribed to the Google Groups "SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools" group.

To unsubscribe from this group and stop receiving emails from it, send an email to scitools-iris+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages