{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!DOCTYPE html>\n",
    "<html>\n",
    "<body>\n",
    "<div align=\"center\">\n",
    "<h3>Prepared by Asif Bhat</h3>\n",
    "    \n",
    "<h1>Data Visualization With Matplotlib</h1>\n",
    "\n",
    "<h3>Follow Me on - <a href=\"https://www.linkedin.com/in/asif-bhat/\">LinkedIn</a>&nbsp; <a href=\"https://mobile.twitter.com/_asifbhat_\">Twitter</a>&nbsp; <a href=\"https://www.instagram.com/datasciencescoop/?hl=en\">Instagram</a>&nbsp; <a href=\"https://www.facebook.com/datasciencescoop/\">Facebook</a></h3>\n",
    "</div>\n",
    "\n",
    "</div>\n",
    "</body>\n",
    "</html>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib as mpl\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Histogram"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 323,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 9528 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "x = np.random.normal(size = 2000)\n",
    "plt.hist(x, bins=40, color='yellowgreen')\n",
    "plt.gca().set(title='Histogram', ylabel='Frequency')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 324,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 8128 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "x = np.random.rand(2000)\n",
    "plt.hist(x, bins=30 ,color='#D4AC0D')\n",
    "plt.gca().set(title='Histogram', ylabel='Frequency')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 325,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 13168 characters]\n",
      "text/plain": [
       "<Figure size 720x576 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Using Edge Color for readability\n",
    "plt.figure(figsize=(10,8))\n",
    "x = np.random.normal(size = 2000)\n",
    "plt.hist(x, bins=40, color='yellowgreen' , edgecolor=\"#6A9662\")\n",
    "plt.gca().set(title='Histogram', ylabel='Frequency')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Binning"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 326,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 13008 characters]\n",
      "text/plain": [
       "<Figure size 720x576 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 11372 characters]\n",
      "text/plain": [
       "<Figure size 720x576 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 11212 characters]\n",
      "text/plain": [
       "<Figure size 720x576 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Binning\n",
    "plt.figure(figsize=(10,8))\n",
    "x = np.random.normal(size = 2000)\n",
    "plt.hist(x, bins=30, color='yellowgreen' , edgecolor=\"#6A9662\")\n",
    "plt.gca().set(title='Histogram', ylabel='Frequency')\n",
    "plt.show()\n",
    "\n",
    "plt.figure(figsize=(10,8))\n",
    "plt.hist(x, bins=20, color='yellowgreen' , edgecolor=\"#6A9662\")\n",
    "plt.gca().set(title='Histogram', ylabel='Frequency')\n",
    "plt.show()\n",
    "\n",
    "plt.figure(figsize=(10,8))\n",
    "plt.hist(x, bins=10, color='yellowgreen' , edgecolor=\"#6A9662\")\n",
    "plt.gca().set(title='Histogram', ylabel='Frequency')\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Plotting Multiple Histograms"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 329,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 13684 characters]\n",
      "text/plain": [
       "<Figure size 576x792 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(8,11))\n",
    "x = np.random.normal(-4,1,size = 800)\n",
    "y = np.random.normal(0,1.5,size = 800)\n",
    "z = np.random.normal(3.5,1,size = 800)\n",
    "plt.hist(x, bins=30, color='yellowgreen' , alpha=0.6)\n",
    "plt.hist(y, bins=30, color='#FF8F00' , alpha=0.6)\n",
    "plt.hist(z, bins=30, color='blue' , alpha=0.6)\n",
    "plt.gca().set(title='Histogram', ylabel='Frequency')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 330,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 14416 characters]\n",
      "text/plain": [
       "<Figure size 720x576 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Using Histogram to plot a cumulative distribution function\n",
    "plt.figure(figsize=(10,8))\n",
    "x = np.random.rand(2000)\n",
    "plt.hist(x, bins=30 ,color='#ffa41b' , edgecolor=\"#639a67\",cumulative=True)\n",
    "plt.gca().set(title='Histogram', ylabel='Frequency')\n",
    "plt.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.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
