.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/plotting/plot_modify_colorbar.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_plotting_plot_modify_colorbar.py: ================================= Modify a Colorbar for your Plot ================================= This is an example of how to modify a colobar within a Py-ART display object. .. GENERATED FROM PYTHON SOURCE LINES 10-21 .. code-block:: Python print(__doc__) # Author: Joe O'Brien (obrienj@anl.gov) # License: BSD 3 clause import cartopy.crs as ccrs import matplotlib.pyplot as plt import pyart from pyart.testing import get_test_data .. GENERATED FROM PYTHON SOURCE LINES 22-29 ** Initial PPI Map Display Let's plot a PPI Map Display and take a look at the colorbar Notice: the colorbar is not perfect and slightly overlaps the PPI display .. GENERATED FROM PYTHON SOURCE LINES 29-78 .. code-block:: Python # Define figure fig = plt.figure() # Create a subplot with correct cartopy projection axs = plt.subplot(111, projection=ccrs.PlateCarree()) # Define and Read in the test data radar_file = get_test_data("swx_20120520_0641.nc") radar = pyart.io.read(radar_file) # Create the Radar Map Display (defines x,y as lat/lons) display = pyart.graph.RadarMapDisplay(radar) # Display the horizontal equivalent reflectivity factor # Note: embellish = False will remove initial lat/lon coords display.plot_ppi_map( "reflectivity_horizontal", 2, ax=axs, vmin=-30, vmax=60, embellish=False, norm=None, cmap="pyart_HomeyerRainbow", ) # Add gridlines gl = axs.gridlines( crs=ccrs.PlateCarree(), draw_labels=True, linewidth=1, color="gray", alpha=0.3, linestyle="--", ) plt.gca().xaxis.set_major_locator(plt.NullLocator()) # Make sure labels are only plotted on the left and bottom gl.top_labels = False gl.right_labels = False gl.xlabel_style = {"size": 14} gl.ylabel_style = {"size": 14} # delete the display object del display .. image-sg:: /examples/plotting/images/sphx_glr_plot_modify_colorbar_001.png :alt: xsapr-sg 2.5 Deg. 2011-05-20T06:42:42Z Equivalent reflectivity factor :srcset: /examples/plotting/images/sphx_glr_plot_modify_colorbar_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 79-80 ** Colorbar Position / Title Manipulation .. GENERATED FROM PYTHON SOURCE LINES 80-131 .. code-block:: Python # Now, let's update the colorbar position # to match the display # Define figure fig = plt.figure() # Create a subplot with correct cartopy projection axsB = plt.subplot(111, projection=ccrs.PlateCarree()) # Create the Radar Map Display (defines x,y as lat/lons) display = pyart.graph.RadarMapDisplay(radar) # Create the display again ppi_map = display.plot_ppi_map( "reflectivity_horizontal", 2, ax=axsB, vmin=-30, vmax=60, embellish=False, norm=None, cmap="pyart_HomeyerRainbow", ) # Add gridlines gl = axsB.gridlines( crs=ccrs.PlateCarree(), draw_labels=True, linewidth=1, color="gray", alpha=0.3, linestyle="--", ) plt.gca().xaxis.set_major_locator(plt.NullLocator()) # Make sure labels are only plotted on the left and bottom gl.top_labels = False gl.right_labels = False # Define the size of the grid labels gl.xlabel_style = {"size": 12} gl.ylabel_style = {"size": 12} # Define the colorbar from the RadarMapDisplay object cbar = display.cbs[0] # Modify the colorbar label and size cbar.set_label(label="Horizontal Reflectivity Factor ($Z_{H}$) (dBZ)", fontsize=12) # Modify the number of colorbar ticks cbar.set_ticks([-20, 0, 20, 40, 60]) .. image-sg:: /examples/plotting/images/sphx_glr_plot_modify_colorbar_002.png :alt: xsapr-sg 2.5 Deg. 2011-05-20T06:42:42Z Equivalent reflectivity factor :srcset: /examples/plotting/images/sphx_glr_plot_modify_colorbar_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.081 seconds) .. _sphx_glr_download_examples_plotting_plot_modify_colorbar.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_modify_colorbar.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_modify_colorbar.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_