Introduction to Matplotlib and Seaborn
Resources for Matplotlib and Seaborn
Cheatsheets
Matplotlib
Matplotlib Tutorial | Matplotlib Gallery | Matplotlib Guide | DataCamp Matplotlib Cheatsheet | Real Python Guide to Matplotlib | Matplotlib Plots Explained
Data and Visualisations with Matplotlib
Seaborn
Seaborn Tutorial | Seaborn Gallery | DataCamp Seaborn Cheatsheet | Seaborn Tutorial | Seaborn Charts | Seaborn Charts 2
What I learnt:
Matplotlib
Basic Plots with Matplotlib
- to install matplotlib in Jupyter notebook,
!pip install matplotlib
- to import matplotlib,
import matplotlib.pyplot as plt
Pyplot is a module of Matplotlib which provides simple functions to add plot elements like lines, images, text, etc. to the current axes in the current figure.
Use help(plt.functionname) to look for help or arguments information for the selected function. e.g. help(plt.hist)
-
plt.plot(list_or_series_1,list_or_series_2) to plot this data as a line chart. We can use two lists as arguments. The first list corresponds to the horizontal axis, and the second list to the vertical axis.
-
plt.show( ) python will wait for the .show( ) function to actually build the plot. The reason for this is that we might want to add some things to our plot before actually displaying it.
-
plt.scatter(list_or_series_1,list_or_series_2) to plot this data as a scatterplot.
-
plt.hist(list_or_series,bins= ) to plot this data in a histogram and with a specified number of bins (ranges of data to display as bars)
Some arguments we can use:
stacked=True
color=’red’
color=[‘red’,’blue’]
Seaborn
- to install Seaborn in Jupyter notebook,
!pip install seaborn
- to import Seaborn,
import seaborn as sns
We can search for the seaborn charts’ functions in https://seaborn.pydata.org/ to look for more information about the function and its arguments.
Additional Resource(s):
Guide to Data Exploration | Difference between histogram, countplot and distplot in Seaborn