{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Hovmoller Diagram of Monthly Surface Temperature\n\nThis example demonstrates the creation of a Hovmoller diagram with fine control\nover plot ticks and labels. The data comes from the Met Office OSTIA project\nand has been pre-processed to calculate the monthly mean sea surface\ntemperature.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.dates as mdates\nimport matplotlib.pyplot as plt\n\nimport iris\nimport iris.plot as iplt\nimport iris.quickplot as qplt\n\n\ndef main():\n    # load a single cube of surface temperature between +/- 5 latitude\n    fname = iris.sample_data_path(\"ostia_monthly.nc\")\n    cube = iris.load_cube(\n        fname,\n        iris.Constraint(\"surface_temperature\", latitude=lambda v: -5 < v < 5),\n    )\n\n    # Take the mean over latitude\n    cube = cube.collapsed(\"latitude\", iris.analysis.MEAN)\n\n    # Now that we have our data in a nice way, lets create the plot\n    # contour with 20 levels\n    qplt.contourf(cube, 20)\n\n    # Put a custom label on the y axis\n    plt.ylabel(\"Time / years\")\n\n    # Stop matplotlib providing clever axes range padding\n    plt.axis(\"tight\")\n\n    # As we are plotting annual variability, put years as the y ticks\n    plt.gca().yaxis.set_major_locator(mdates.YearLocator())\n\n    # And format the ticks to just show the year\n    plt.gca().yaxis.set_major_formatter(mdates.DateFormatter(\"%Y\"))\n\n    iplt.show()\n\n\nif __name__ == \"__main__\":\n    main()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.10.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}