Background colour when plotting masked Cube

97 views
Skip to first unread message

Simon Peatman

unread,
Apr 10, 2017, 8:19:02 AM4/10/17
to Iris
I am using iris.plot to create a contourf of a Cube which has a masked array.  I would like all missing values to be greyed out.  Using matplotlib I can achieve this by setting axisbg when creating an axis object, but this has no effect in Iris:

import iris
import iris.plot as iplt
import matplotlib.pyplot as plt

cube
= iris.load_cube('test.nc')

ax
= plt.subplot(121, axisbg='0.5')
plt
.contourf(cube.coord('longitude').points, cube.coord('latitude').points, cube.data)
ax
= plt.subplot(122, axisbg='0.5')
iplt
.contourf(cube)
plt
.show()

As far as missing values are concerned, the first plot gives me exactly what I want but the second has the missing regions in white (see attached image).  Is there any way of setting the missing regions to grey in Iris plot?
test.nc
test.png

Andrew Dawson

unread,
Apr 10, 2017, 4:14:32 PM4/10/17
to Iris
When you use subplot you are creating normal matplotlib axes, and when you use iris to plot a cube over a map (default for cubes with geographical coordinates) iris has to replace the provided axes with a GeoAxes instance from cartopy. When it does this replacement it doesn't carry all properties with it. The solution here is to set the background color *after* calling the iris plot function (probably something like ax.set_axis_bgcolor will do), or create GeoAxes from the get-go so iris doesn't have to replace them..
Reply all
Reply to author
Forward
0 new messages