{
 "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 Python (Matplotlib - Part 1)</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": [
    "# Donut plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 27184 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",
    "my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre\n",
    "p=plt.gcf()\n",
    "p.gca().add_artist(my_circle)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 27220 characters]\n",
      "text/plain": [
       "<Figure size 648x648 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Changing background color\n",
    "fig = plt.figure(figsize=(9,9))\n",
    "fig.patch.set_facecolor('#DADADA') # Changing background color of donut chart\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",
    "my_circle=plt.Circle( (0,0), 0.7, color='#DADADA') # Adding circle at the centre\n",
    "p=plt.gcf()\n",
    "p.gca().add_artist(my_circle)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Explode Slice in Donut Chart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 28068 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 , explode=[0,0 , 0.0 , 0.1])\n",
    "my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre\n",
    "p=plt.gcf()\n",
    "p.gca().add_artist(my_circle)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 28728 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 , explode=[0,0 , 0.1 , 0.1])\n",
    "my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre\n",
    "p=plt.gcf()\n",
    "p.gca().add_artist(my_circle)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 28540 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 , explode=[0.03,0.03 , 0.03 , 0.03])\n",
    "my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre\n",
    "p=plt.gcf()\n",
    "p.gca().add_artist(my_circle)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Displaying percentage and actual values in Donut Chart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 30184 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 , autopct='%1.1f%%', explode=[0,0 , 0 , 0])\n",
    "my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre\n",
    "p=plt.gcf()\n",
    "p.gca().add_artist(my_circle)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 29940 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 , autopct='%1.1f%%', pctdistance=0.85 ,explode=[0,0 , 0 , 0])\n",
    "my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre\n",
    "p=plt.gcf()\n",
    "p.gca().add_artist(my_circle)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 32748 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",
    "total = np.sum(tickets)\n",
    "\n",
    "def val_per(x): \n",
    "    return '{:.2f}%\\n({:.0f})'.format(x, total*x/100)\n",
    "\n",
    "labels = ['Low' , 'Medium' , 'High' , 'Critical']\n",
    "colors = ['#8BC34A','#D4E157','#FFB300','#FF7043']\n",
    "plt.pie (tickets , labels= labels , colors= colors , startangle=45 , autopct=val_per, pctdistance=0.85 ,explode=[0,0 , 0 , 0])\n",
    "my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre\n",
    "p=plt.gcf()\n",
    "p.gca().add_artist(my_circle)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Display multiple Donut plots in one figure"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 52316 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",
    "my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre\n",
    "p=plt.gcf()\n",
    "p.gca().add_artist(my_circle)\n",
    "\n",
    "plt.subplot(1,3,2)\n",
    "plt.pie (tickets , labels= status , colors= colors , startangle=45)\n",
    "my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre\n",
    "p=plt.gcf()\n",
    "p.gca().add_artist(my_circle)\n",
    "\n",
    "plt.subplot(1,3,3)\n",
    "plt.pie (tickets , labels= company , colors= colors , startangle=45)\n",
    "my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre\n",
    "p=plt.gcf()\n",
    "p.gca().add_artist(my_circle)\n",
    "\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 104736 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",
    "plt.subplot(2,3,1)\n",
    "plt.pie (tickets , labels= priority , colors= colors , startangle=45)\n",
    "my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre\n",
    "p=plt.gcf()\n",
    "p.gca().add_artist(my_circle)\n",
    "\n",
    "plt.subplot(2,3,2)\n",
    "plt.pie (tickets , labels= status , colors= colors , startangle=45)\n",
    "my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre\n",
    "p=plt.gcf()\n",
    "p.gca().add_artist(my_circle)\n",
    "\n",
    "plt.subplot(2,3,3)\n",
    "plt.pie (tickets , labels= company , colors= colors , startangle=45)\n",
    "my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre\n",
    "p=plt.gcf()\n",
    "p.gca().add_artist(my_circle)\n",
    "\n",
    "\n",
    "plt.subplot(2,3,4)\n",
    "plt.pie (tickets , labels= priority , colors= colors , startangle=45)\n",
    "my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre\n",
    "p=plt.gcf()\n",
    "p.gca().add_artist(my_circle)\n",
    "\n",
    "plt.subplot(2,3,5)\n",
    "plt.pie (tickets , labels= status , colors= colors , startangle=45)\n",
    "my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre\n",
    "p=plt.gcf()\n",
    "p.gca().add_artist(my_circle)\n",
    "\n",
    "plt.subplot(2,3,6)\n",
    "plt.pie (tickets , labels= company , colors= colors , startangle=45)\n",
    "my_circle=plt.Circle( (0,0), 0.7, color='white') # Adding circle at the centre\n",
    "p=plt.gcf()\n",
    "p.gca().add_artist(my_circle)\n",
    "\n",
    "plt.show()\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.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
