{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Data for plotting\n",
    "t = np.arange(0.0, 2.0, 0.01)\n",
    "s = 1 + np.sin(2 * np.pi * t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig, ax = plt.subplots()\n",
    "ax.plot(t, s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig, ax = plt.subplots()\n",
    "ax.set(xlabel='time (s)', ylabel='voltage (mV)', title='Adding labels')\n",
    "ax.plot(t, s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig, ax = plt.subplots()\n",
    "ax.set(xlabel='time (s)', ylabel='voltage (mV)', title='Adding labels')\n",
    "ax.grid()\n",
    "ax.plot(t, s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig.savefig(\"test.png\") # to save image as a file\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x1 = np.linspace(0.0, 5.0)\n",
    "x2 = np.linspace(0.0, 2.0)\n",
    "\n",
    "y1 = np.cos(2 * np.pi * x1) * np.exp(-x1)\n",
    "y2 = np.cos(2 * np.pi * x2)\n",
    "\n",
    "plt.subplot(2, 1, 1)\n",
    "plt.plot(x1, y1, 'o-')\n",
    "plt.title('A tale of 2 subplots')\n",
    "plt.ylabel('Damped oscillation')\n",
    "\n",
    "plt.subplot(2, 1, 2)\n",
    "plt.plot(x2, y2, '.-')\n",
    "plt.xlabel('time (s)')\n",
    "plt.ylabel('Undamped')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "np.random.seed(19680801)\n",
    "\n",
    "# example data\n",
    "mu = 100  # mean of distribution\n",
    "sigma = 15  # standard deviation of distribution\n",
    "x = mu + sigma * np.random.randn(437)\n",
    "\n",
    "num_bins = 50\n",
    "\n",
    "fig, ax = plt.subplots()\n",
    "\n",
    "# the histogram of the data\n",
    "n, bins, patches = ax.hist(x, num_bins, density=1)\n",
    "\n",
    "# add a 'best fit' line\n",
    "y = ((1 / (np.sqrt(2 * np.pi) * sigma)) *\n",
    "     np.exp(-0.5 * (1 / sigma * (bins - mu))**2))\n",
    "ax.plot(bins, y, '--')\n",
    "ax.set_xlabel('Smarts')\n",
    "ax.set_ylabel('Probability density')\n",
    "ax.set_title(r'Histogram of IQ: $\\mu=100$, $\\sigma=15$')\n",
    "\n",
    "# Tweak spacing to prevent clipping of ylabel\n",
    "fig.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.path as mpath\n",
    "import matplotlib.patches as mpatches\n",
    "# import matplotlib.pyplot as plt\n",
    "\n",
    "fig, ax = plt.subplots()\n",
    "\n",
    "Path = mpath.Path\n",
    "path_data = [\n",
    "    (Path.MOVETO, (1.58, -2.57)),\n",
    "    (Path.CURVE4, (0.35, -1.1)),\n",
    "    (Path.CURVE4, (-1.75, 2.0)),\n",
    "    (Path.CURVE4, (0.375, 2.0)),\n",
    "    (Path.LINETO, (0.85, 1.15)),\n",
    "    (Path.CURVE4, (2.2, 3.2)),\n",
    "    (Path.CURVE4, (3, 0.05)),\n",
    "    (Path.CURVE4, (2.0, -0.5)),\n",
    "    (Path.CLOSEPOLY, (1.58, -2.57)),\n",
    "    ]\n",
    "codes, verts = zip(*path_data)\n",
    "path = mpath.Path(verts, codes)\n",
    "patch = mpatches.PathPatch(path, facecolor='r', alpha=0.5)\n",
    "ax.add_patch(patch)\n",
    "\n",
    "# plot control points and connecting lines\n",
    "x, y = zip(*path.vertices)\n",
    "line, = ax.plot(x, y, 'go-')\n",
    "\n",
    "ax.grid()\n",
    "ax.axis('equal')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from matplotlib.ticker import MaxNLocator\n",
    "from collections import namedtuple\n",
    "\n",
    "\n",
    "n_groups = 5\n",
    "\n",
    "means_men = (20, 35, 30, 35, 27)\n",
    "std_men = (2, 3, 4, 1, 2)\n",
    "\n",
    "means_women = (25, 32, 34, 20, 25)\n",
    "std_women = (3, 5, 2, 3, 3)\n",
    "\n",
    "fig, ax = plt.subplots()\n",
    "\n",
    "index = np.arange(n_groups)\n",
    "bar_width = 0.35\n",
    "\n",
    "opacity = 0.4\n",
    "error_config = {'ecolor': '0.3'}\n",
    "\n",
    "rects1 = ax.bar(index, means_men, bar_width,\n",
    "                alpha=opacity, color='b',\n",
    "                yerr=std_men, error_kw=error_config,\n",
    "                label='Men')\n",
    "\n",
    "rects2 = ax.bar(index + bar_width, means_women, bar_width,\n",
    "                alpha=opacity, color='r',\n",
    "                yerr=std_women, error_kw=error_config,\n",
    "                label='Women')\n",
    "\n",
    "ax.set_xlabel('Group')\n",
    "ax.set_ylabel('Scores')\n",
    "ax.set_title('Scores by group and gender')\n",
    "ax.set_xticks(index + bar_width / 2)\n",
    "ax.set_xticklabels(('A', 'B', 'C', 'D', 'E'))\n",
    "ax.legend()\n",
    "\n",
    "fig.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# Pie chart, where the slices will be ordered and plotted counter-clockwise:\n",
    "labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'\n",
    "sizes = [15, 30, 45, 10]\n",
    "explode = (0, 0.1, 0, 0)  # only \"explode\" the 2nd slice (i.e. 'Hogs')\n",
    "\n",
    "fig1, ax1 = plt.subplots()\n",
    "ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',\n",
    "        shadow=True, startangle=90)\n",
    "ax1.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
