In [1]:
import iris
import iris.plot as iplt
import iris.quickplot as qplt
import matplotlib.pyplot as plt

cube = iris.load_cube(iris.sample_data_path('A1B_north_america.nc'))
print(cube.summary(True))


air_temperature / (K)               (time: 240; latitude: 37; longitude: 49)
/Users/dawson/miniconda3/envs/pfcs/lib/python3.5/site-packages/iris/fileformats/cf.py:1140: IrisDeprecation: NetCDF default loading behaviour currently does not expose variables which define reference surfaces for dimensionless vertical coordinates as independent Cubes. This behaviour is deprecated in favour of automatic promotion to Cubes. To switch to the new behaviour, set iris.FUTURE.netcdf_promote to True.
  warn_deprecated(msg)

Exercise 6: Use the a1b sample data ('A1B_north_america.nc'), with appropriate slicing, to produce the following:

1. a contour plot of longitude vs time


In [10]:
qplt.contour(cube[:, 0])
plt.show()


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-fb7bae987e6d> in <module>()
----> 1 qplt.contour(cube[:, 0])
      2 plt.show()

/Users/dawson/miniconda3/envs/pfcs/lib/python3.5/site-packages/iris/quickplot.py in contour(cube, *args, **kwargs)
    159     """
    160     coords = kwargs.get('coords')
--> 161     result = iplt.contour(cube, *args, **kwargs)
    162     _label_with_points(cube, coords=coords)
    163     return result

/Users/dawson/miniconda3/envs/pfcs/lib/python3.5/site-packages/iris/plot.py in contour(cube, *args, **kwargs)
    687 
    688     """
--> 689     result = _draw_2d_from_points('contour', None, cube, *args, **kwargs)
    690     return result
    691 

/Users/dawson/miniconda3/envs/pfcs/lib/python3.5/site-packages/iris/plot.py in _draw_2d_from_points(draw_method_name, arg_func, cube, *args, **kwargs)
    393             result = draw_method(*args, **kwargs)
    394         else:
--> 395             result = draw_method(u, v, data, *args, **kwargs)
    396 
    397         # Apply tick labels for string coordinates.

/Users/dawson/miniconda3/envs/pfcs/lib/python3.5/site-packages/matplotlib/pyplot.py in contour(*args, **kwargs)
   2771         ax.hold(hold)
   2772     try:
-> 2773         ret = ax.contour(*args, **kwargs)
   2774     finally:
   2775         ax.hold(washold)

/Users/dawson/miniconda3/envs/pfcs/lib/python3.5/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
   1817                     warnings.warn(msg % (label_namer, func.__name__),
   1818                                   RuntimeWarning, stacklevel=2)
-> 1819             return func(ax, *args, **kwargs)
   1820         pre_doc = inner.__doc__
   1821         if pre_doc is None:

/Users/dawson/miniconda3/envs/pfcs/lib/python3.5/site-packages/matplotlib/axes/_axes.py in contour(self, *args, **kwargs)
   5617             self.cla()
   5618         kwargs['filled'] = False
-> 5619         return mcontour.QuadContourSet(self, *args, **kwargs)
   5620     contour.__doc__ = mcontour.QuadContourSet.contour_doc
   5621 

/Users/dawson/miniconda3/envs/pfcs/lib/python3.5/site-packages/matplotlib/contour.py in __init__(self, ax, *args, **kwargs)
   1422         are described in QuadContourSet.contour_doc.
   1423         """
-> 1424         ContourSet.__init__(self, ax, *args, **kwargs)
   1425 
   1426     def _process_args(self, *args, **kwargs):

/Users/dawson/miniconda3/envs/pfcs/lib/python3.5/site-packages/matplotlib/contour.py in __init__(self, ax, *args, **kwargs)
    861         self._transform = kwargs.get('transform', None)
    862 
--> 863         self._process_args(*args, **kwargs)
    864         self._process_levels()
    865 

/Users/dawson/miniconda3/envs/pfcs/lib/python3.5/site-packages/matplotlib/contour.py in _process_args(self, *args, **kwargs)
   1443                 self._corner_mask = mpl.rcParams['contour.corner_mask']
   1444 
-> 1445             x, y, z = self._contour_args(args, kwargs)
   1446 
   1447             _mask = ma.getmask(z)

/Users/dawson/miniconda3/envs/pfcs/lib/python3.5/site-packages/matplotlib/contour.py in _contour_args(self, args, kwargs)
   1526             args = args[1:]
   1527         elif Nargs <= 4:
-> 1528             x, y, z = self._check_xyz(args[:3], kwargs)
   1529             args = args[3:]
   1530         else:

/Users/dawson/miniconda3/envs/pfcs/lib/python3.5/site-packages/matplotlib/contour.py in _check_xyz(self, args, kwargs)
   1553         self.ax._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
   1554         x = self.ax.convert_xunits(x)
-> 1555         y = self.ax.convert_yunits(y)
   1556 
   1557         x = np.asarray(x, dtype=np.float64)

/Users/dawson/miniconda3/envs/pfcs/lib/python3.5/site-packages/matplotlib/artist.py in convert_yunits(self, y)
    197         if ax is None or ax.yaxis is None:
    198             return y
--> 199         return ax.yaxis.convert_units(y)
    200 
    201     def set_axes(self, axes):

/Users/dawson/miniconda3/envs/pfcs/lib/python3.5/site-packages/matplotlib/axis.py in convert_units(self, x)
   1442             return x
   1443 
-> 1444         ret = self.converter.convert(x, self.units, self)
   1445         return ret
   1446 

/Users/dawson/miniconda3/envs/pfcs/lib/python3.5/site-packages/nc_time_axis/__init__.py in convert(cls, value, unit, axis)
    259 
    260         if not isinstance(first_value, CalendarDateTime):
--> 261             raise ValueError('The values must be numbers or instances of '
    262                              '"nc_time_axis.CalendarDateTime".')
    263 

ValueError: The values must be numbers or instances of "nc_time_axis.CalendarDateTime".

2. a contourf map (of the first timestep) on a LambertConformal projection (with coastlines)


In [4]:
import cartopy.crs as ccrs
ax = plt.axes(projection=ccrs.LambertConformal())
ax.coastlines()
iplt.contourf(cube[0])
plt.show()


3. a block plot (pcolormesh) map (of the first timestep) in its native projection (with coastlines)


In [5]:
iplt.pcolormesh(cube[0])
plt.gca().coastlines()
plt.show()


/Users/dawson/miniconda3/envs/pfcs/lib/python3.5/site-packages/iris/coords.py:802: UserWarning: Coordinate 'longitude' is not bounded, guessing contiguous bounds.
  'contiguous bounds.'.format(self.name()))
/Users/dawson/miniconda3/envs/pfcs/lib/python3.5/site-packages/iris/coords.py:802: UserWarning: Coordinate 'latitude' is not bounded, guessing contiguous bounds.
  'contiguous bounds.'.format(self.name()))

4. a line plot showing forecast_period vs air_temperature for the first latitude and longitude points (hint: plot accepts two arguments for the x and y axes)


In [6]:
series = cube[:, 0, 0]
qplt.plot(series.coord('forecast_period'), series)
plt.show()


5. a scatter plot showing longitude vs air_temperature for the first time and latitude points


In [7]:
lon_slice = cube[0, 20, :]
qplt.scatter(lon_slice.coord('longitude'), lon_slice)
plt.show()



In [ ]: