{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# NCL_box_1.py\n\nThis script illustrates the following concepts:\n   - Drawing box plots\n   - Manipulating boxplot vizualizations\n   - Manipulating plot axes\n\nSee following URLs to see the reproduced NCL plot & script:\n    - Original NCL script: https://www.ncl.ucar.edu/Applications/Scripts/box_1.ncl\n    - Original NCL plot: https://www.ncl.ucar.edu/Applications/Images/box_1_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 fake data:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "seed = 200\nnp.random.seed(seed)\n\ndata = np.random.lognormal(size=(40, 3), mean=1, sigma=.7)\nfor a in range(len(data)):\n    data[a] = [x - 4 for x in data[a]]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Create figure and axis\nw = 0.25\nfig, ax = plt.subplots(figsize=(6, 6))\nboxplots = ax.boxplot(data,\n                      labels=['Control', '-2Xna', '2Xna'],\n                      widths=[w, w, w],\n                      showfliers=False)\n\n# Set whiskers style to dashed\nplt.setp(boxplots['whiskers'], linestyle='--')\n\n# Set median line to black\nplt.setp(boxplots['medians'], color='black')\n\n# Remove axis lines on top and right sides\nax.spines['right'].set_visible(False)\nax.spines['top'].set_visible(False)\n\n# Use geocat.viz.util convenience function to set axes tick values\ngvutil.set_axes_limits_and_ticks(ax,\n                                 ylim=(-6.0, 9.0),\n                                 yticks=[-3.0, 0.0, 3.0, 6.0])\n\n# Use geocat.viz.util convenience function to add minor and major tick lines\ngvutil.add_major_minor_ticks(ax,\n                             y_minor_per_major=3,\n                             x_minor_per_major=1,\n                             labelsize=14)\n\n# Use geocat.viz.util convenience function to add title to the plot axis.\ngvutil.set_titles_and_labels(ax, maintitle='Default Box Plot')\n\n# Make both major and minor ticks point inwards towards the plot\nax.tick_params(direction=\"in\", which='both')\n\n# Set ticks only at left and bottom sides of plot\nax.yaxis.set_ticks_position('left')\nax.xaxis.set_ticks_position('bottom')\n\n# Display Plot\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
}