{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# NCL_conwomap_3.py\nConcepts illustrated:\n  - Drawing a simple contour plot\n  - Generating dummy data using \"random_normal\"\n  - Drawing a filled polygon over area on a contour plot with missing data\n  - Turning off the bottom and right borders of a contour plot\n  - Changing the labels and tickmarks on a contour plot\n  - Adding a complex Greek character to a contour plot\n  - Moving the contour informational label into the plot\n  - Forcing tickmarks and labels to be drawn on the top X axis in a contour plot\n\nSee following URLs to see the reproduced NCL plot & script:\n    - Original NCL script: https://www.ncl.ucar.edu/Applications/Scripts/conwomap_3.ncl\n    - Original NCL plot: https://www.ncl.ucar.edu/Applications/Images/conwomap_3_lg.png\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Import packages:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nimport matplotlib.pyplot as plt\n\nfrom geocat.viz import util as gvutil"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Generate random data:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "xlist = np.linspace(0, 31.0, 31)\nylist = np.linspace(0, 31.0, 31)\nxdata, ydata = np.meshgrid(xlist, ylist)\n\nzdata = np.random.normal(0, 3.0, size=(31, 31))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Create figure\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plt.figure(figsize=(10, 10))\n\n# Create axes\nax = plt.axes()\n\n# Use geocat.viz.util convenience function to set axes limits & tick values without calling several matplotlib functions\ngvutil.set_axes_limits_and_ticks(ax,\n                                 xlim=(0, 30),\n                                 ylim=(0, 30),\n                                 xticks=None,\n                                 yticks=None,\n                                 xticklabels=None,\n                                 yticklabels=None)\n\n# Use geocat.viz.util to add major and minor tics\ngvutil.add_major_minor_ticks(ax,\n                             x_minor_per_major=5,\n                             y_minor_per_major=5,\n                             labelsize=18)\n\n# Use geocat.viz.util convenience function to add titles to left and right of the plot axis.\ngvutil.set_titles_and_labels(ax, ylabel=\"wave number\", labelfontsize=24)\n\n# Set ticks and labels only on left and top of plot\nax.xaxis.tick_top()\nax.yaxis.tick_left()\n\n# Set color of right and bottom axes to make them invisible\nax.spines['right'].set_color('white')\nax.spines['bottom'].set_color('white')\n\n# Create a numpy array of the length of xlist\nx = np.arange(0, len(xlist))\n\n# Plot a step function\nplt.step(x, x, color='black', zorder=7)\n\n# Plot contour data\ncp = ax.contour(xdata, ydata, zdata, colors='black', linewidths=1.0)\n\n# Label contours\nax.clabel(cp, inline=True, fontsize=10, colors='black', fmt=\"%.0f\")\n\n# Ignore second half of the graph\ny1 = np.full(shape=len(xlist), fill_value=0, dtype=np.int)\ny2 = x\nax.fill_between(x,\n                y1,\n                y2,\n                where=y2 >= y1,\n                color='white',\n                step='pre',\n                alpha=1.0,\n                zorder=4)\n\n# Set properties for the text boxes\nprops1 = dict(facecolor='white', edgecolor='white', alpha=0.5)\nprops2 = dict(facecolor='white', edgecolor='black', alpha=0.5)\n\n# Place first text box\nax.text(0.70,\n        0.35,\n        'J(${\\u03B1}$)',\n        transform=ax.transAxes,\n        fontsize=25,\n        bbox=props1,\n        zorder=5)\n\n# Place second text box\nax.text(0.70,\n        0.05,\n        'CONTOUR FROM -8 TO 6 BY 1',\n        transform=ax.transAxes,\n        fontsize=10,\n        bbox=props2,\n        zorder=5)\n\nplt.show()"
      ]
    }
  ],
  "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.7.9"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}