{
 "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": [
    "# Pie Charts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 23292 characters]\n",
      "text/plain": [
       "<Figure size 648x648 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(9,9))\n",
    "tickets = [48 , 30 , 20 , 15]\n",
    "labels = ['Low' , 'Medium' , 'High' , 'Critical']\n",
    "colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']\n",
    "plt.pie (tickets , labels= labels , colors= colors , startangle=45)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Display percentage and actual value in Pie Chart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 29404 characters]\n",
      "text/plain": [
       "<Figure size 576x576 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Display percentage in Pie Chart using autopct='%1.1f%%' \n",
    "plt.figure(figsize=(8,8))\n",
    "tickets = [48 , 30 , 20 , 15]\n",
    "labels = ['Low' , 'Medium' , 'High' , 'Critical']\n",
    "colors = ['#7CB342','#C0CA33','#FFB300','#F57C00']\n",
    "plt.pie (tickets , labels= labels , colors= colors , startangle=45 , shadow='true', autopct='%1.1f%%', explode=[0,0 , 0 , 0])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 32120 characters]\n",
      "text/plain": [
       "<Figure size 576x576 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(8,8))\n",
    "tickets = [48 , 30 , 20 , 15]\n",
    "total = np.sum(tickets)\n",
    "labels = ['Low' , 'Medium' , 'High' , 'Critical']\n",
    "\n",
    "def val_per(x): \n",
    "    return '{:.2f}%\\n({:.0f})'.format(x, total*x/100)\n",
    "\n",
    "colors = ['#7CB342','#C0CA33','#FFB300','#F57C00']\n",
    "plt.pie (tickets , labels= labels , colors= colors , startangle=45 , shadow='true', autopct=val_per, explode=[0,0 , 0 , 0])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Explode Slice in Pie Chart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 33192 characters]\n",
      "text/plain": [
       "<Figure size 576x576 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#Explode 4th Slice\n",
    "plt.figure(figsize=(8,8))\n",
    "tickets = [48 , 30 , 20 , 15]\n",
    "labels = ['Low' , 'Medium' , 'High' , 'Critical']\n",
    "colors = ['#7CB342','#C0CA33','#FFB300','#F57C00']\n",
    "# explode = [0,0,0,0.1] will explode the fourth slice\n",
    "plt.pie (tickets , labels= labels , colors= colors , startangle=45 , autopct='%1.1f%%' , shadow='true', explode=[0,0 , 0 , 0.1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 39596 characters]\n",
      "text/plain": [
       "<Figure size 576x576 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#Explode 3rd & 4th Slice\n",
    "plt.figure(figsize=(8,8))\n",
    "tickets = [48 , 30 , 20 , 15]\n",
    "label = ['Low' , 'Medium' , 'High' , 'Critical']\n",
    "color = ['#7CB342','#C0CA33','#FFB300','#F57C00']\n",
    "# explode = [0,0,0.1,0.1] will explode the 3rd & 4th slice\n",
    "plt.pie (tickets , labels= label , colors= color , startangle=45 ,autopct='%1.1f%%', shadow='true', explode=[0,0 , 0.1 , 0.1])\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Display multiple pie plots in one figure"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 43844 characters]\n",
      "text/plain": [
       "<Figure size 1440x432 with 3 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure(figsize=(20,6))\n",
    "tickets = [48 , 30 , 20 , 15]\n",
    "priority = ['Low' , 'Medium' , 'High' , 'Critical']\n",
    "status = ['Resolved' , 'Cancelled' , 'Pending' , 'Assigned']\n",
    "company = ['IBM' , 'Microsoft', 'BMC' , 'Apple']\n",
    "colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']\n",
    "\n",
    "plt.subplot(1,3,1)\n",
    "plt.pie (tickets , labels= priority , colors= colors , startangle=45)\n",
    "\n",
    "\n",
    "plt.subplot(1,3,2)\n",
    "plt.pie (tickets , labels= status , colors= colors , startangle=45)\n",
    "\n",
    "\n",
    "plt.subplot(1,3,3)\n",
    "plt.pie (tickets , labels= company , colors= colors , startangle=45)\n",
    "\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 93120 characters]\n",
      "text/plain": [
       "<Figure size 1440x936 with 6 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure(figsize=(20,13))\n",
    "tickets = [48 , 30 , 20 , 15]\n",
    "priority = ['Low' , 'Medium' , 'High' , 'Critical']\n",
    "status = ['Resolved' , 'Cancelled' , 'Pending' , 'Assigned']\n",
    "company = ['IBM' , 'Microsoft', 'BMC' , 'Apple']\n",
    "colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']\n",
    "\n",
    "\n",
    "plt.subplot(2,3,1)\n",
    "plt.pie (tickets , labels= priority , colors= colors , startangle=45 , autopct='%1.1f%%')\n",
    "\n",
    "\n",
    "plt.subplot(2,3,2)\n",
    "plt.pie (tickets , labels= status , colors= colors , startangle=45 , autopct='%1.1f%%')\n",
    "\n",
    "\n",
    "plt.subplot(2,3,3)\n",
    "plt.pie (tickets , labels= company , colors= colors , startangle=45 , autopct='%1.1f%%')\n",
    "\n",
    "\n",
    "\n",
    "plt.subplot(2,3,4)\n",
    "plt.pie (tickets , labels= priority , colors= colors , startangle=45, autopct='%1.1f%%')\n",
    "\n",
    "\n",
    "plt.subplot(2,3,5)\n",
    "plt.pie (tickets , labels= status , colors= colors , startangle=45 ,autopct='%1.1f%%')\n",
    "\n",
    "\n",
    "plt.subplot(2,3,6)\n",
    "plt.pie (tickets , labels= company , colors= colors , startangle=45, autopct='%1.1f%%')\n",
    "\n",
    "\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
}
