.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated/gallery/meteorology/plot_hovmoller.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_generated_gallery_meteorology_plot_hovmoller.py: Hovmoller Diagram of Monthly Surface Temperature ================================================ This example demonstrates the creation of a Hovmoller diagram with fine control over plot ticks and labels. The data comes from the Met Office OSTIA project and has been pre-processed to calculate the monthly mean sea surface temperature. .. GENERATED FROM PYTHON SOURCE LINES 11-52 .. image-sg:: /generated/gallery/meteorology/images/sphx_glr_plot_hovmoller_001.png :alt: Surface temperature :srcset: /generated/gallery/meteorology/images/sphx_glr_plot_hovmoller_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.dates as mdates import matplotlib.pyplot as plt import iris import iris.plot as iplt import iris.quickplot as qplt def main(): # load a single cube of surface temperature between +/- 5 latitude fname = iris.sample_data_path("ostia_monthly.nc") cube = iris.load_cube( fname, iris.Constraint("surface_temperature", latitude=lambda v: -5 < v < 5), ) # Take the mean over latitude cube = cube.collapsed("latitude", iris.analysis.MEAN) # Now that we have our data in a nice way, lets create the plot # contour with 20 levels qplt.contourf(cube, 20) # Put a custom label on the y axis plt.ylabel("Time / years") # Stop matplotlib providing clever axes range padding plt.axis("tight") # As we are plotting annual variability, put years as the y ticks plt.gca().yaxis.set_major_locator(mdates.YearLocator()) # And format the ticks to just show the year plt.gca().yaxis.set_major_formatter(mdates.DateFormatter("%Y")) iplt.show() if __name__ == "__main__": main() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.302 seconds) .. _sphx_glr_download_generated_gallery_meteorology_plot_hovmoller.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_hovmoller.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_hovmoller.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_