.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/XArray_Projections.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_XArray_Projections.py: ========================== XArray Projection Handling ========================== Use MetPy's XArray accessors to simplify opening a data file and plotting data on a map using CartoPy. .. GENERATED FROM PYTHON SOURCE LINES 12-36 .. image-sg:: /examples/images/sphx_glr_XArray_Projections_001.png :alt: XArray Projections :srcset: /examples/images/sphx_glr_XArray_Projections_001.png :class: sphx-glr-single-img .. code-block:: default import cartopy.feature as cfeature import matplotlib.pyplot as plt import xarray as xr # Any import of metpy will activate the accessors from metpy.cbook import get_test_data ds = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False)) data_var = ds.metpy.parse_cf('Temperature') x = data_var.x y = data_var.y im_data = data_var.isel(time=0).sel(isobaric=1000.) fig = plt.figure(figsize=(14, 14)) ax = fig.add_subplot(1, 1, 1, projection=data_var.metpy.cartopy_crs) ax.imshow(im_data, extent=(x.min(), x.max(), y.min(), y.max()), cmap='RdBu', origin='lower' if y[0] < y[-1] else 'upper') ax.coastlines(color='tab:green', resolution='10m') ax.add_feature(cfeature.LAKES.with_scale('10m'), facecolor='none', edgecolor='tab:blue') ax.add_feature(cfeature.RIVERS.with_scale('10m'), edgecolor='tab:blue') plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 7.557 seconds) .. _sphx_glr_download_examples_XArray_Projections.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: XArray_Projections.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: XArray_Projections.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_