{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Seaborn: Strip Plot" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Strip Plot\n", "\n", "Welcome back to another lecture on visualizing *categorical data* with Seaborn! In the last lecture, we discussed in detail the importance of Categorical data and general representation. In this lecture, we shall continue from where we left previously. Our discussion has majorly been around beeswarm visualization using Seaborn's Swarmplot. Today, we are going to discuss another important type of plot, i.e. **Strip Plot**, which is pretty similar to what we have already seen previously. \n", "\n", "- A **[Strip Plot](http://seaborn.pydata.org/generated/seaborn.stripplot.html?highlight=stripplot#seaborn.stripplot)** can be drawn on its own, but it is also a good complement to a box or violin plot in cases where you want to show all observations along with some representation of the underlying distribution.\n", "\n", "So, let us begin by importing our requisities, that we have gathered over time. Then, slowly we shall start exploring parameters and scenarios where this plot could come in handy for us:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2021-11-16T07:12:55.759509Z", "start_time": "2021-11-16T07:12:10.603239Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Matplotlib is building the font cache; this may take a moment.\n" ] } ], "source": [ "# Importing intrinsic libraries:\n", "import numpy as np\n", "import pandas as pd\n", "np.random.seed(0)\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "%matplotlib inline\n", "sns.set(style=\"whitegrid\", palette=\"rocket\")\n", "import warnings\n", "warnings.filterwarnings(\"ignore\")\n", "\n", "# Let us also get tableau colors we defined earlier:\n", "tableau_20 = [(31, 119, 180), (174, 199, 232), (255, 127, 14), (255, 187, 120),\n", " (44, 160, 44), (152, 223, 138), (214, 39, 40), (255, 152, 150),\n", " (148, 103, 189), (197, 176, 213), (140, 86, 75), (196, 156, 148),\n", " (227, 119, 194), (247, 182, 210), (127, 127, 127), (199, 199, 199),\n", " (188, 189, 34), (219, 219, 141), (23, 190, 207), (158, 218, 229)]\n", "\n", "# Scaling above RGB values to [0, 1] range, which is Matplotlib acceptable format:\n", "for i in range(len(tableau_20)):\n", " r, g, b = tableau_20[i]\n", " tableau_20[i] = (r / 255., g / 255., b / 255.)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We have already observed **Strip Plot** representation earlier as well so let us plot it at a basic level once again to begin our discussion with:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2021-11-16T07:12:56.256301Z", "start_time": "2021-11-16T07:12:55.759509Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " | total_bill | \n", "tip | \n", "sex | \n", "smoker | \n", "day | \n", "time | \n", "size | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "16.99 | \n", "1.01 | \n", "Female | \n", "No | \n", "Sun | \n", "Dinner | \n", "2 | \n", "
1 | \n", "10.34 | \n", "1.66 | \n", "Male | \n", "No | \n", "Sun | \n", "Dinner | \n", "3 | \n", "
2 | \n", "21.01 | \n", "3.50 | \n", "Male | \n", "No | \n", "Sun | \n", "Dinner | \n", "3 | \n", "
3 | \n", "23.68 | \n", "3.31 | \n", "Male | \n", "No | \n", "Sun | \n", "Dinner | \n", "2 | \n", "
4 | \n", "24.59 | \n", "3.61 | \n", "Female | \n", "No | \n", "Sun | \n", "Dinner | \n", "4 | \n", "