0% found this document useful (0 votes)
12 views

Introduction Tom at Plot Lib

Uploaded by

Jeril Joy Joseph
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Introduction Tom at Plot Lib

Uploaded by

Jeril Joy Joseph
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 38

INTRODUCTION TO

MATPLOTLIB
Matplotlib is an amazing visualization library in Python for 2D plots of
arrays
• Matplotlib is an amazing visualization library in Python for 2D plots of
arrays
• Matplotlib is a multi-platform data visualization library built on
NumPy arrays and designed to work with the broader SciPy stack. It
was introduced by John Hunter in the year 2002.
• One of the greatest benefits of visualization is that it allows us visual
access to huge amounts of data in easily digestible visuals.
• Matplotlib consists of several plots like line, bar, scatter, histogram
etc
Importing matplotlib :
• from matplotlib import pyplot as plt or
• import matplotlib.pyplot as plt
Basic plots in Matplotlib :

• Matplotlib comes with a wide variety of plots.


• Plots helps to understand trends, patterns, and to make correlations.
• They’re typically instruments for reasoning about quantitative
information.
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()
Bar 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 the bar
• plt.bar(x,y)

• # function to show the plot
• plt.show()
Histogram :
• # importing matplotlib module
• from matplotlib import pyplot as plt

• # Y-axis values
• y = [10, 5, 8, 4, 2]

• # Function to plot histogram
• plt.hist(y)

• # Function to show the plot
• plt.show()
Scatter 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 scatter
• plt.scatter(x, y)

• # function to show the plot
• plt.show()
Functional Approach:
Matplotlib allows us easily create multi-plots on the same figure using
the .subplot() method. This .subplot() method takes in three parameters, namely:

 nrows: the number of rows


the Figure should have.
 ncols: the number of columns
the Figure should have.
 plot_number : which refers to a specific
plot in the Figure.
Using .subplot() we will create a two plots on the same canvas:
Object oriented Interface:

This is the best way to create plots.


The idea here is to create Figure objects and call methods off it.
Let’s create a blank Figure using the .figure() method
Next step
• Now we need to add a set of axes
• .add_axes()
• (left, bottom, width, and height)
Something interesting , figure in figure
We can create a matrix of subplot for
example 3*3
Add ,
plot.tight_layout()
The only difference between plt.figure() and
plt.subplots() is that
plt.subplots() automatically does
what the .add_axes() method of .figure()
will do for you based off
the number of rows and columns you specify.
Figure size, aspect ratio, and DPI IN
FIGURE
IN SUBPLOTS
THE BROTHER CAN SAVE PICTURE ALSO
VIA
FIG.SAVEFIG(‘NAME.PNG’)
Legends

• Legends allows us to distinguish between


plots. With Legends, you can use label texts
to identify or differentiate one plot from
another. For example, say we have a figure
having two plots like below:
Plot Types
• HISTOGRAM
• HELPS US UNDERSTAND THE DISTRIBUTION OF NUMERIC VALUE IN A
WAY THAT YOU CAN NOT DO WITH MEAN , MEDIAN , MODE
Time series (Line Plot)
• is a chart that shows a trend over a period of
time.
• It allows you to test various hypotheses under
certain conditions, like what happens different
days of the week or between different times of
the day.
EXAMPLE
Scatter plots
• offer a convenient way to visualize how two numeric values are
related in your data.
• It helps in understanding relationships between multiple variables.
• Using .scatter() method, we can create a scatter plot:
• EXAMPLE
Bar graphs
• are convenient for comparing numeric values of several groups.
Using .bar() method, we can create a bar graph:
WHAT YOU HAVE LEARN AND WHY
• FOR DATA VISUALIZATION
• WE CAN INTEGRATE THE VISUALIZATION TECHNIQUE IN OUR ML MODEL
• WE CAN SELL VISUALIZATIONS TO COMPANY BY THEIR DATA
• HOWEVER , IF YOU WANT TO BECOME
• >>> DATA ANALYST
• >>>>>>>>MASTER THIS LIBRARY YOU WILL GET HIRED AT PACKAGE OF
• *** 5.5 LPA **
• PLOTLY , SEABORN AND MATPLOTLIB ARE REPLACEMENT FOR EACH
OTHER

You might also like