What is Matplotlib ? Basic Operations on MatplotLib
What is MatplotLib | Basic Operations on MatplotLib | MatplotLib Example
What is MatplotLib?
Introduction
Matplotlib is a library in Python Programming Language, which provides an object-oriented API for embedding plots into applications using general-purpose GUI toolkits like Tkinter, wxPython, Qt or GTK+. It was originally written by John D.Hunter.
Installation
python -mpip install -U matplotlib
Importing Matplotlib
from matplotlib import pyplot as plt
or
import matplotlib.pyplot as plt
Performing Line Plot
# importing matplotlib module
from matplotlib import pyplot as plt
# x-axis values
x = [5, 2, 9, 4, 7]
# Y-axis values
y = [10, 5, 8, 4, 2]
# Function to plot
plt.plot(x,y)
# function to show the plot
plt.show()
Performing Bar Plot
# importing matplotlib module
from matplotlib import pyplot as plt
# x-axis values
x = [5,8,6,1,3]
# Y-axis values
y = [3,5,9,7,6]
# Function to plot
plt.bar(x,y)
# function to show the plot
plt.show()
Performing Scatter Plot
# importing matplotlib module
from matplotlib import pyplot as plt
# x-axis values
x = [5,8,6,1,3]
# Y-axis values
y = [3,5,9,7,6]
# Function to plot
plt.scatter(x,y)
# function to show the plot
plt.show()
Performing Histogram
# importing matplotlib module
from matplotlib import pyplot as plt
# Y-axis values
y = [15,6,8,6,22]
# Function to plot histogram
plt.hist(y)
# Function to show the plot
plt.show()