-
Notifications
You must be signed in to change notification settings - Fork 300
Closed
Labels
Description
There is a really niche bug in Iris that causes plotting to fail with an AttributeError in the very specific case of plotting mappable* data into an inset axes** that was not originally defined as a Cartopy GeoAxes instance with use of the projection kwarg.
* By mappable data I mean any data that will be drawn to a Cartopy GeoAxes instance.
** By an inset axes I mean a new axes instance with a positional rect defined.
The following code demonstrates the problem:
import iris
import iris.plot as iplt
import matplotlib.pyplot as plt
fname = iris.sample_data_path("air_temp.pp")
cube = iris.load_cube(fname)
fig = plt.figure()
ax1 = plt.axes()
ax2 = plt.axes([.17, .65, .2, .2])
plt.sca(ax1)
iplt.contourf(cube)
plt.sca(ax2)
iplt.pcolormesh(cube)
plt.show()which produces the following traceback:
Traceback (most recent call last):
File "test_code.py", line 92, in <module>
main()
File "test_code.py", line 87, in main
a_different_approach(cube, x, y, c)
File "test_code.py", line 53, in a_different_approach
iplt.pcolormesh(cube)
File "/opt/ukmo/iris/default/linux64/site-packages/iris/plot.py", line 783, in pcolormesh
result = _draw_2d_from_bounds('pcolormesh', cube, *args, **kwargs)
File "/opt/ukmo/iris/default/linux64/site-packages/iris/plot.py", line 235, in _draw_2d_from_bounds
cube, plot_defn, *args, **kwargs)
File "/opt/ukmo/iris/default/linux64/site-packages/iris/plot.py", line 528, in _map_common
kwargs)
File "/opt/ukmo/iris/default/linux64/site-packages/iris/plot.py", line 467, in _geoaxes_draw_method_and_kwargs
draw_method = getattr(ax, draw_method_name)
AttributeError: 'NoneType' object has no attribute 'pcolormesh'
Adding a projection kwarg to the definition of ax2 works around the problem because the problem code in iris.plot._replace_axes_with_cartopy_axes is not run to return a NoneType that causes the AttributeError.