.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plotting/plot_skewt_with_text.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_auto_examples_plotting_plot_skewt_with_text.py: Skew-T plot of a sounding ------------------------- This example shows how to make a Skew-T plot from a sounding and calculate stability indicies. Author: Maxwell Grover .. GENERATED FROM PYTHON SOURCE LINES 11-72 .. image-sg:: /auto_examples/plotting/images/sphx_glr_plot_skewt_with_text_001.png :alt: twpsondewnpnC3.b1 on 20060121 :srcset: /auto_examples/plotting/images/sphx_glr_plot_skewt_with_text_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import xarray as xr from arm_test_data import DATASETS from matplotlib import pyplot as plt import act # Make sure attributes are retained xr.set_options(keep_attrs=True) # Read data filename_sonde = DATASETS.fetch('twpsondewnpnC3.b1.20060121.231600.custom.cdf') sonde_ds = act.io.arm.read_arm_netcdf(filename_sonde) # Calculate stability indicies sonde_ds = act.retrievals.calculate_stability_indicies( sonde_ds, temp_name='tdry', td_name='dp', p_name='pres' ) # Plot the stability index values on the plot variables = [ 'lifted_index', 'surface_based_cape', 'surface_based_cin', 'most_unstable_cape', 'most_unstable_cin', 'lifted_condensation_level_temperature', 'lifted_condensation_level_pressure', ] # Add a helper function which will format the text def format_variable(variable, rounding_digits=2): """Format a sounding variable to displayed on a single line""" return f'{variable}: {np.round(sonde_ds[variable], rounding_digits).values} {sonde_ds[variable].units}' # Setup the plot skewt = act.plotting.SkewTDisplay(sonde_ds, figsize=(12, 8)) # Add the stability indices ax = skewt.axes[0] props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) for i in range(len(variables)): ax.text( 0.05, (0.98 - (0.05 * i)), format_variable(variables[i]), transform=ax.transAxes, fontsize=10, verticalalignment='top', bbox=props, ) # Add data skewt.plot_from_u_and_v('u_wind', 'v_wind', 'pres', 'tdry', 'dp', shade_cin=False) sonde_ds.close() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.407 seconds) .. _sphx_glr_download_auto_examples_plotting_plot_skewt_with_text.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_skewt_with_text.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_skewt_with_text.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_skewt_with_text.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_