{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "# The Lifecycle of a Plot\n",
    "\n",
    "\n",
    "This notebook is a summary that aims to show the beginning, middle, and end of a single\n",
    "visualization using Matplotlib. We'll begin with some raw data and\n",
    "end by saving a figure of a customized visualization. Along the way we'll try\n",
    "to highlight some neat features and best-practices using Matplotlib.\n",
    "\n",
    "Our data\n",
    "========\n",
    "\n",
    "We'll use the data from the post from which this tutorial was derived.\n",
    "It contains sales information for a number of companies."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# sphinx_gallery_thumbnail_number = 10\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from matplotlib.ticker import FuncFormatter\n",
    "\n",
    "data = {'Barton LLC': 109438.50,\n",
    "        'Frami, Hills and Schmidt': 103569.59,\n",
    "        'Fritsch, Russel and Anderson': 112214.71,\n",
    "        'Jerde-Hilpert': 112591.43,\n",
    "        'Keeling LLC': 100934.30,\n",
    "        'Koepp Ltd': 103660.54,\n",
    "        'Kulas Inc': 137351.96,\n",
    "        'Trantow-Barrows': 123381.38,\n",
    "        'White-Trantow': 135841.99,\n",
    "        'Will LLC': 104437.60}\n",
    "group_data = list(data.values())\n",
    "group_names = list(data.keys())\n",
    "group_mean = np.mean(group_data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Getting Started\n",
    "=============\n",
    "\n",
    "First lets generate our figure containing out axes. Recall: the Figure is like a canvas, and the Axes is a part of that canvas on which we will make a particular visualization.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 4824 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = plt.subplots()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Once we have our figure and axes, we can generate our plot within them."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<BarContainer object of 10 artists>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 13816 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = plt.subplots()\n",
    "ax.barh(group_names, group_data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Things to notice:\n",
    "* There is no heading on the plot.\n",
    "* X-axis is missing a label.\n",
    "* It is difficult to compare the bars because there is no backing grid to line up the bar ends.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Applying Style to a Plot\n",
    "===================\n",
    "\n",
    "Matplotlib has a wide range of built-in style sheets that can be used to modify the appearance of plots. Styles are applied to the pyplot object and we must re-make plots between style changes to see the results.\n",
    "\n",
    "[Review the stylesheet reference](https://matplotlib.org/3.1.0/gallery/style_sheets/style_sheets_reference.html)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['bmh', 'classic', 'dark_background', 'fast', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn-bright', 'seaborn-colorblind', 'seaborn-dark-palette', 'seaborn-dark', 'seaborn-darkgrid', 'seaborn-deep', 'seaborn-muted', 'seaborn-notebook', 'seaborn-paper', 'seaborn-pastel', 'seaborn-poster', 'seaborn-talk', 'seaborn-ticks', 'seaborn-white', 'seaborn-whitegrid', 'seaborn', 'Solarize_Light2', 'tableau-colorblind10', '_classic_test']\n"
     ]
    }
   ],
   "source": [
    "print(plt.style.available)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can activate a desired style using the `plyplot.style.use( ... )` function."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.style.use('seaborn-bright')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we can re-make the plot using the new style."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<BarContainer object of 10 artists>"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 19140 characters]\n",
      "text/plain": [
       "<Figure size 576x396 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = plt.subplots()\n",
    "ax.barh(group_names, group_data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The style controls many things, such as color, linewidths, backgrounds, etc. Not all styles apply to all types of plots. You should experiment to see how the appearance of different plot-types are affected."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Customizing a Plot\n",
    "=================\n",
    "\n",
    "\n"
   ]
  }
 ],
 "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.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
