.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/calculations/Divergence.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_calculations_Divergence.py: ========== Divergence ========== Use `metpy.calc.divergence`. This example demonstrates the calculation of total deformation using the example xarray Dataset and plotting using Matplotlib. .. GENERATED FROM PYTHON SOURCE LINES 14-36 .. image-sg:: /examples/calculations/images/sphx_glr_Divergence_001.png :alt: Horizontal Divergence Calculation :srcset: /examples/calculations/images/sphx_glr_Divergence_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import metpy.calc as mpcalc from metpy.cbook import example_data # load example data ds = example_data() # Calculate the total deformation of the flow div = mpcalc.divergence(ds.uwind, ds.vwind) # start figure and set axis fig, ax = plt.subplots(figsize=(5, 5)) # plot divergence and scale by 1e5 cf = ax.contourf(ds.lon, ds.lat, div * 1e5, range(-15, 16, 1), cmap=plt.cm.bwr_r) plt.colorbar(cf, pad=0, aspect=50) ax.barbs(ds.lon.values, ds.lat.values, ds.uwind, ds.vwind, color='black', length=5, alpha=0.5) ax.set(xlim=(260, 270), ylim=(30, 40)) ax.set_title('Horizontal Divergence Calculation') plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.115 seconds) .. _sphx_glr_download_examples_calculations_Divergence.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Divergence.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Divergence.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: Divergence.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_