Seaborn Is The Easier Matplotlib
Key Takeaways
This video covers the basics of Seaborn, a Python data visualization library based on Matplotlib, and demonstrates its use in creating various statistical graphs and plots, including scatter plots, histograms, bar plots, and heat maps.
Full Transcript
[Music] what is going on guys welcome back in today's that i'm going to give you a brief introduction into the seabourn module in python and the seabourn module is a wrapper around matplotlib so it uses matplotlib and it allows you to design to create attractive and good-looking statistical graphs that are quite complex so it provides a level interface it makes it easier for you to create such graphs and this is what we're going to take a look at today so let's get right into it all right now for today's tutorial i'm going to use an ipython notebook or more specifically a jupiter notebook and i recommend you do so as well because that allows you to execute individual cells of code so you don't have to run the whole script when you change something or add something you can just run individual cells and all the variables or data sets are still stored in the ram so let me show you quickly an example here if i say a equals 10 now i'm in a new cell and i can just say print a and i can go down here and say print a plus one and i don't have to constantly execute all of the statements that come before which is particularly useful if we work with data sets and visualizations so i don't have to look at all the graphs that i have plotted before um in order to see the newest graph and i don't have to delete code in order to be faster i can just run individual cells which makes a lot of sense when working with data sets however if you don't want to use an ipython notebook you can also just use pycharm vs code idle vim whatever you can just run the same python code that we write today in the jupyter notebook also in another development environment but it's more convenient to use an ipython notebook so having said that the first thing we want to do is we want to install seaburn and for that we open up a command line and we type pip install seaborn if you are using an anaconda environment i assume you already know how to install packages usually with conda install seaborn uh even though you can also use pip there if you want to once we have that we can start by importing seaborne sns which is the usual alias and then we can just um get started with some data sets because for the visualization we need data sets and you can use whatever data set you want i'm just gonna talk about general visualization functions here you can use a data set from kaggle you can use a csv file that you have on your computer you can use stock data from the pandas data reader if you want to or you can also just go ahead and say sns get underscore data set underscore names and you can pick one of those data sets that are provided by seaborne automatically or built in here um and we're going to just load a couple of them here we're going to say uh tips equals sns load underscore data set tips then we're gonna say iris equals load iris and then titanic load titanic and then um planets load planets just so we have some data sets here and the first one that we're going to look at is going to be tips so we can just type tips and we're going to see here as a pandas data frame what this looks like we have the total bill we have the tip we have the sex we have the smoker yes no we have the day of the week we have the time when when this meal was consumed and then we have the size of the meal at the restaurant so this can be used for tip prediction whatever we're not going to do any machine learning today we're just going to visualize the data and the first thing that we can do here is we can plot a simple scatter plot by saying sns scatter plot so basically just the individual data points and we're going to say that the x value that we want to plot here is the tip so how much was tipped whereas the y is the value of the total bill the data set is the tips data set that we loaded here and then we're going to also first of all let's let's just do it like that so we can see a very simple graph like this one here nothing fancy about it but now we can do something like uh hue and this is going to be the day so this year and now we have categories represented in colors so now you can see okay if it's saturday it's green if it's thursday it's blue and so on and we can add some more information we can say for example the size of the individual data points is the size of the data set so depending on the size of the meal we're going to change the size of the individual data points so this is a very small meal this is a larger meal [Music] and then we can also change the color palette i hope this is how it's pronounced um and this is going to be yellow green blue like that and now we can see this is already quite an informative visualization and we didn't have to really do anything we just said okay x value is a tip which is numeric then the y value is the total bill which is also numeric so quite simple to plot on a coordinate system and then we just passed uh the day which is a categorical value here and it's now um determining the color and then we pass the size which is a numerical value to determine the size so we didn't have to really think about how to do something we didn't really have to spend a lot of time looking up certain conventions or anything or certain functions that we have to use we just pass the individual fields and seaborne automatically generates a very informative scatter plot now we have different types of plots so this is probably the most simple one for me a scatter plot is always the most simple plot possible because we basically just take two coordinates and we point we plot a single point a single data point and then we do that for uh all the rows but we also have some more um statistical type of plots like histograms or distribution plots and for that we can for example say sns.hist plot so histogram plot and we pass your tips tip so we're interested in the tip of the tips and we're going to say kde equals true to get the line as well and we can specify the bins of the histogram so in this case here this is the distribution of the tips very few people um give a tip around that value so now i think tip is in dollars right so we don't have a lot of people tipping ten dollars we have very uh many people tipping around two dollars or three or something like that between two and four basically um and we can see here the distribution function we can also see more if i say bins equals 30 we can see more bins if i say bins equals five we're going to get less information here i think 15 is quite a good value and if i say kde equals true is no longer the case we don't have this line here this function so this is a very simple one we can also plot it in a different way though so i can also say um sns dist plot for distribution plot and i can pass the same value so tips tip kde equals true and bins equals 15 and this is almost the same function even though what does it say here future oh yeah it's a deprecated function that's why we have the same function so don't use the disk plot function use the uh hist plot but right now i recognize actually the t is something i didn't want to have here because we have the disc plot which is deprecated we have the hist plot which is not deprecated and we also have the dis plot without a t which is essentially very similar to the his plot so i can actually copy this here and change this back to an h and add a t and you're going to see that they're quite similar this one is a little bit larger when it comes to the vertical line but essentially they're the same plot from the information now then we also have bar plots bar plots are very very uh simple plots as well we just say sns bar plot and then we can say okay on the x-axis i want to have the sex so male or female on the y-axis i want to have the tip so we can see if there's a difference between the genders um and then we can say the data is tips and the palette is gonna be yellow green blue like that so this gives us some information we can see that on average we have a slight um slightly higher bar on male so males seem to give more tips usually but this could also be because males maybe eat larger meals we don't know yet so this is not something that we can see in that visualization that's a very very simple bar chart a more complicated statistical chart would be a box plot which can easily be plotted with seaborne as well by just saying sns.box plot and here we're going to say okay now we want to see what the distribution of tipping is on particular days so on saturday sunday friday and so on um compared to the total bill data is tips or actually we want to in this case let's change this to tips um in this case we'll look at the tips otherwise we'll look at the meal size or actually the total the total bill amount and the color is gonna be the gender and then we're going to choose the same color scheme here yellow blue green actually green blue sorry and we have a problem here tip i think tip without an s right there you go so you can see here that on the different days we have this different distributions we can also look at the total bill which is probably uh not too different but we can see for example that the the center line here for those of you who don't know how to read a box plot this is the median so the central value uh those are the quartiles and um so basically the quartiles all the are the four sections of the box plot this is the maximum this is the minimum and then we have some outliers that are not considered um but here you can see how easily we can plot the distribution also blue meaning uh female and green meaning male that is quite simple in matplotlib to get this plot with that information would be more complicated so seaborn makes this way easier for us we can also plot something similar even though it's not exactly the same as a box plot we can plot a strip plot so it doesn't have information about the quartiles and the medians but we can see the distribution of the data points easier so we can say x equals day y equals tip for example and then data equals tips again and we're going to say dodge equals true dodge equals true is important because let me show you what happens if we don't do that and then we're going to set the same color scheme so yellow green blue so this is what happens if you don't dodge and if we now set dodge equal to true we can see that the genders are separated and now you can see the distribution of tipping you can see that males usually um are higher you could say so on saturdays we have a lot of high tips that are coming from males um here as well actually for for each weekday this is the case even though we have also some males that don't really tip a lot which is yeah at least on friday and sunday seems like this is not the case for females we have fewer females down here even though they always occupy i'm not sure about saturday but other than saturday they always occupy the minimum position so one could uh further examine that if we were doing some data science work here um now let's get to some more complicated plots because those are still quite simple let's do some joint plots which are essentially a scatter plot and a distribution plot at the same time so what we do here is we say s and s joint plot and the x value is for example the tip the y value is the total bill and the data is tips and then we can just plot this joint plot here and what you see is that we have a scatter plot and also we have 40 individual features so four tip and four total bill here the distribution function this is quite interesting um of a plot to look at because it's a combined plot and again the main focus on seabourn is always it makes it easy for you everything you do here with seaborn can be done in matplotlib as well the main emphasis here is how easy it is to do that you just take a data set you just set them set some um values here and then you get a very good looking and very informative plots now we can add some more stuff to that we can also say kind equals rec for regression and then we see here a regression line and also uh the distribution function here as well so this is also quite simple now i haven't played around with that but maybe we can also determine the color here i'm not sure no doesn't work in this case um maybe there's a different keyword for that but usually you just look up the documentation you see a bunch of different options and usually it's enough to just specify um a column of of some of the features here so basically just taking something like size or time and this is gonna already be translated automatically without you having to turn it into numerical values first or something into a color into a size into something like that now we can also change the kind here from regression to kde and this then turns it into something like that this is more like a a three-dimensional uh plot here where you can see okay the main concentration is here and then the further out you go the less instances you have here now if you want to see this better or more obvious you can also set the shade to true then you can see where the concentration of values is so here we have a lot of values here we have less values and here we have no values basically and that again can be influenced by setting a color map so color map equals yellow green blue again with a lowercase u and you can see here that we have a pretty good looking plot that shows us that most values are here now we can also change that slightly by changing the kind here to hex now we have hexagons actually what's the problem here uh we don't have shade in hexagons and hex plots so this is basically the same thing we have most values here here here here here but now we have this as hexagons so this is also quite interesting all sorts of different plots here now one of the more complicated plots or one of the more um i know bigger plots is a pair plot basically combining the individual features in the pair plot how can this be done we can just say s s dot pair plot and then we can pass a data set for this one it probably makes sense to not use the tips let's see what the titanic data set looks like yeah this this looks like something that can be quite interesting so pair sns pair plot and then titanic dot and we're going to just select the numeric values because we cannot uh use categorical values here so select underscore d types number to just get the numerical values and then the color is going to be determined by p class for those of you who have watched my titanic video uh the data set analysis here they know that the uh class of the person is very highly correlated with the survival so if we do that we can see here a pier plot which is quite a large plot you can see here the different features plotted against each other so we can see survived and survived whenever we have the same value so the value plotted against itself it would be just a straight line so a correlation of one um because of that we get a distribution function here distribution plot and for the other values we have the values plotted against against each other which is quite cool now then we get to one of my favorite plots which is one that i use in a lot of videos and whenever i explore a data set for prediction of something i always use that because that is really something that's very important whenever you have a data set like the titanic data set for example where you want to know how can i best predict the survival you want to look at correlations and when you look at correlations when you have a data set like titanic for example you can call the core function to get the correlations between the individual uh values and this is fine because here you already have all the information you need but it's very hard to find the values especially if you have more features than that um it is not a good overview because you just have numbers and you you really have to look for numbers here um it makes more sense to put that into a heat map a heat map is based basically showing you where you have high values by showing you colors so let me show you what that looks like we can just say sns.heatmap and we're going to pass your titanic dot core for the correlation we're going to set not equals true so the annotations uh this basically just means we're going to also see the numbers and then we're going to say the c map is going to be yellow green blue again and then you have this very beautiful heat map whatever is closer to dark blue is highly correlated um with each other so if we have for example uh something what is a very high correlation something like 0.41 this means that the siblings and what was p arch i think parents children is highly correlated so if we have someone with siblings they probably also have parents uh or children or something like that uh on on board and negative correlations are also important so when something is highly negatively correlated it's also interesting because that does not mean it's irrelevant irrelevance is close to zero that basically means there's no correlation negative correlation also gives us information so for example we have something like 0 5 8 here and this is negatively correlated to a loan so when you have parents or children you're probably not alone obviously or something like that so we can also use other color maps like cool warm here which might make more sense the hotter something is the more correlated it is the colder it is uh so the more blue it is uh the less the more negatively it is correlated and the more white it is or gray uh the more it is close to having not any correlation at all and we also have different color maps like ice fire or something like that and yeah this is one of my favorite plots this is one i actually use very often whenever i look into a data set and i want to predict something i always look okay which features are correlated especially if i want to predict the survival i want to know which of the features is highly correlated with survival so here you can see what is that adult male if you are an adult male you're probably not going to survive or the probability of you surviving is not very high as we can see here um now last but not least i want to show you a plot that i'm not actually quite sure i understand so i don't want to talk too much about how it works here um but i want to just show you that plot because it is essentially a dendogram it is a cluster map sns dot cluster map and now we can take i don't know let's take the iris data set we're going to take um i think we cannot just plot the iris data set i think we need to drop the features that are not numeric so the species we're going to drop the species axis one and now we have this cluster map here essentially this is clustering the individual instances um obviously into clusters and this is indicated by colors again don't ask me about any details about this plot but it can be quite useful uh if you're dealing with unsupervised learning and if you want to visualize clusters probably it makes more sense for smaller plots so it doesn't have to look as chaotic as that but the individual colors here are representing clusters so those are definitely not all the plot types that you can find in seabourn i recommend you check out the documentation there are a lot of interesting and more advanced examples you can do much more with seaborne if you go into the different parameters if you go into different settings but this is a quite simple thing to do this is a very easy to plot something like this which already gives us a lot of information about where is the data how is it distributed and especially i again emphasize it heat maps are very useful when you first look into a data set to see which values which features are highly correlated so that's it for today's video i hope you enjoyed it and i hope you'll learn something if so let me know by hitting the like button leaving a comment in the comment section down below and of course don't forget to subscribe to this channel and hit the notification bell to not miss a single future video for free other than that thank you much for watching see you next video and bye [Music] you
Original Description
This video is about Seaborn, an external Python data visualization library, which is based on Matplotlib.
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
🐍 The Python Bible Book: https://www.neuralnine.com/books/
💻 The Algorithm Bible Book: https://www.neuralnine.com/books/
👕 Programming Merch: https://www.neuralnine.com/shop
🌐 Social Media & Contact 🌐
📱 Website: https://www.neuralnine.com/
📷 Instagram: https://www.instagram.com/neuralnine
🐦 Twitter: https://twitter.com/neuralnine
🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/
📁 GitHub: https://github.com/NeuralNine
🎙 Discord: https://discord.gg/JU4xr8U3dm
🎵 Outro Music From: https://www.bensound.com/
Timestamps:
(0:00) Intro
(0:36) Seaborn Datasets
(3:17) Scatter Plot
(6:00) Histograms & Distribution Plots
(8:15) Bar Plot
(9:04) Box Plot & Strip Plot
(12:20) Join Plot
(15:30) Pair Plot
(17:05) Heat Map
(20:19) Cluster Map
(22:05) Outro
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from NeuralNine · NeuralNine · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
Python Beginner Tutorial #5 - Loops
NeuralNine
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
Python Beginner Tutorial #7 - Functions
NeuralNine
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
Python Beginner Tutorial #9 - File Operations
NeuralNine
Python Beginner Tutorial #10 - String Functions
NeuralNine
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
Python Intermediate Tutorial #6 - Queues
NeuralNine
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
Python Intermediate Tutorial #9 - Recursion
NeuralNine
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
Python Intermediate Tutorial #11 - Logging
NeuralNine
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
Python Machine Learning #4 - Support Vector Machines
NeuralNine
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
Making Text Images Readable Again with Python and OpenCV
NeuralNine
Neural Networks Simply Explained (Theory)
NeuralNine
Motion Filtering with OpenCV in Python
NeuralNine
Top 5 Programming Languages To Learn in 2020
NeuralNine
Simple TCP Chat Room in Python
NeuralNine
Image Classification with Neural Networks in Python
NeuralNine
Edge Detection with OpenCV in Python
NeuralNine
S&P 500 Web Scraping with Python
NeuralNine
Simple Sentiment Text Analysis in Python
NeuralNine
Introduction - Algorithms & Data Structures #1
NeuralNine
More on: ML Maths Basics
View skill →Related Reads
📰
📰
📰
📰
3 Python + Data Warehouse Patterns I Use in Every Production Pipeline
Medium · Python
CKAN is your backend, not your frontend
Dev.to · Anuar Ustayev
PGA Best Online Data Analytics Courses in India 2026: What the Placement Data Actually Shows
Medium · Python
Breaking Down Punjab Kings’ Bowling Attack: What Statistics Reveal About IPL 2026
Medium · Data Science
🎓
Tutor Explanation
DeepCamp AI