Exploring Matplotlib and Seaborn

Pavini Jain
3 min readJun 13, 2021

--

Matplotlib is a plotting library for the Python programming language and its numerical mathematics extension NumPy. Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics.

Table of Content

  1. Importing libraries
  2. Line Graph
  3. Multi-line Graph
  4. Scatterplot
  5. Histogram
  6. Bar Graph
  7. Pair Plot

Importing Libraries

import matplotlib.pyplot as pltimport seaborn as snsimport numpy as np

Line Graph

apples = [11,45,23,76,34]years = [2000,2001,2002,2003,2004]plt.xlabel(years)plt.ylabel(apples)plt.plot(years,apples)

Multi-line Graph

apples = [11,45,23,76,34]years = [2000,2001,2002,2003,2004]plt.xlabel(years)plt.ylabel(apples)plt.plot(years,apples)oranges = [23,34,54,22,67]plt.plot(years,oranges)plt.title('Graph')plt.legend(['apples','oranges'])
apples = [11,45,23,76,34]years = [2000,2001,2002,2003,2004]plt.xlabel(years)plt.ylabel(apples)plt.plot(years,apples,marker='^')oranges = [23,34,54,22,67]plt.plot(years,oranges,marker='*')plt.title('Graph')plt.legend(['apples','oranges'])
sns.set_style('darkgrid')apples = [11,45,23,76,34]years = [2000,2001,2002,2003,2004]plt.xlabel(years)plt.ylabel(apples)plt.plot(years,apples,marker='^')oranges = [23,34,54,22,67]plt.plot(years,oranges,marker='*')plt.title('Graph')plt.legend(['apples','oranges'])
plt.plot(flowers_df.sepal_length,flowers_df.sepal_width)

Scatterplot

apples = [11,45,23,76,34]years = [2000,2001,2002,2003,2004]plt.xlabel(years)plt.ylabel(apples)plt.plot(years,apples,'or',color='yellow')oranges = [23,34,54,22,67]plt.plot(years,oranges,'or')plt.title('Graph')plt.legend(['apples','oranges'])
flowers_df=sns.load_dataset("iris")flowers_df
sns.scatterplot(x=flowers_df.sepal_length,y=flowers_df.sepal_width)
sns.scatterplot(x=flowers_df.sepal_length,y=flowers_df.sepal_width)
flowers_df.sepal_width

Histogram

plt.title('Distribution of sepal width')plt.hist(flowers_df.sepal_width)
plt.title('Distribution of sepal width')plt.hist(flowers_df.sepal_width,bins=15)
plt.title('Distribution of sepal width')plt.hist(flowers_df.sepal_width,bins=[2,3,4])
plt.title('Distribution of sepal width')plt.hist(flowers_df.sepal_width,bins=np.arange(2,5,0.25))
tips_df=sns.load_dataset('tips')tips_df

Bar Graph

plt.bar(tips_df.size,tips_df.total_bill)
sns.barplot(x=tips_df.day,y=tips_df.total_bill)
sns.barplot(x=tips_df.day,y=tips_df.total_bill,data=tips_df)
sns.barplot(x=tips_df.day,y=tips_df.total_bill,data=tips_df,hue='sex')

Pair Plot

sns.pairplot(flowers_df, hue='species');

If you found this article useful, you can clap and to stay updated with my articles you can follow me.

--

--

Pavini Jain

Student at Jaypee Institute of Information Technology