More On Matplotlib

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 43

INSTITUTE - UIE

DEPARTMENT- ACADEMIC UNIT-1


Bachelor of Engineering (Computer Science &
Engineering)
SUBJECT NAME:- Disruptive Technologies – I
SUBJECT CODE- 21ECP102
Prepared By: Dr. Amandeep Sharma

TOPIC:- More on Matplotlib DISCOVER . LEARN . EMPOWER


1
Course Objectives
S. No. Objectives

1 To develop an understanding of the building blocks of AI.

2 To aware about Data Science/Analytics.

To provide knowledge about Cloud Computing as presented in terms of intelligent agents: search, knowledge representation,
3 inference, logic, and learning.

4 To make familiar with Matplotlib.

5 To give brief knowledge about Disruptive Technologies.

2
Course Outcomes Why Data Visualization?

CO Title Level
Number

CO1 Grasp the characteristics of disruptive technologies and Remember


understand building blocks of artificial intelligence, data science
and cloud computing.
CO2 Develop simple intelligent system using available tools and Understand
techniques of AI to analyze and interpret domain knowledge.
CO3 Build effective data visualizations, and learn to work with data Apply
through the entire data science process.
CO4 Deploy, build, and monitor cloud-based applications. Analyze and
evaluate
CO5 Work in a team that can propose, design, implement and report on Create
their selected domain. https://in.pinterest.com/pin/2406611738233
16229/

3
OBJECTIVE
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.
Theory
1. Importing matplotlib :
• from matplotlib import pyplot as plt

Or

• import matplotlib.pyplot as plt


2. 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.
A. 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()
B. Bar plot :
• # importing matplotlib module
• from matplotlib import pyplot as plt

• # x-axis values
• x = [5, 2, 9, 4, 7]

• # Y-axis value
s
•• y = [10, 5, 8, 4, 2]
• # Function to plot the bar
• plt.bar(x,y)

• # function to show the plot
• plt.show()
C. 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()
D. Scatter Plot :
• # importing matplotlib module
• from matplotlib import pyplot as plt

• # x-axis values
• x = [5, 2, 9, 4, 7]

• # Y-axis value
s
•• y = [10, 5, 8, 4, 2]
• # Function to plot scatter
• plt.scatter(x, y)

• # function to show the plot
• plt.show()
3. Functional Approach

Figure 1. Line graph through Matplotlib


Figure 2. Line graph through
Matplotlib with labels
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
• ncols: the number of columns
• plot_number: which refers to a specific plot in
the Figure.
Using .subplot() we will create a two plots on the same canvas:

Figure 3. subplot in Matplotlib


4. 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)
Figure 4. Line graph through Matplotlib with axes selection
Something interesting , Figure in Figure

Figure 5. Depicting Figure in Figure(a)


Figure 5. Depicting Figure in Figure(b)
We can create a matrix of subplot for example 3*3

Figure 6. Matrix of subplots in matplotlib


5. 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 7. Selective insertion of graph
6. Figure size, aspect ratio, and DPI

Figure 8. Selection of figure size, aspect ratio, and DPI(a)


7. IN SUBPLOTS

Figure 8. Selection of figure size, aspect ratio, and DPI(b)


Figure 9. Use of imshow
8. 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 on next page.
Figure 10. Use of Legends(a)
Figure 10. Use of Legends(b)
PLOT TYPES

1. Histogram
• Helps us understand the distribution of numeric
value in a way that you can not do with mean,
median, mode.
Figure 11. Use of Histograms
2. Time series (Line Plot)
• It 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.
EXAMP
LE

Figure 12. Time Series based Line Plot


3. Scatter plots
• They 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.
Figure 13. Scatter Plot
4. Bar graphs
• They are convenient for comparing numeric values of several groups.

• Using .bar() method, we can create a bar graph.


Figure 14. Bar Graphs
Learning Outcomes
On completion of the course students will be able to understand

• Grasp the characteristics of disruptive technologies and understand building


blocks of artificial intelligence, data science and cloud computing.
• Develop simple intelligent system using available tools and techniques of AI to
analyze and interpret domain knowledge.
• Build effective data visualizations, and learn to work with data through the
entire data science process.
• Deploy, build, and monitor cloud-based applications.
• Work in a team that can propose, design, implement and report on their
selected domain.
39
Viva Voice Questions
1.Identify the package manager for Python packages, or modules.
2. Which is a python package used for 2D graphics?
3. To install matplotlib, the following function will be typed in your
command prompt. What does “-U”represents?
4. which function of matplotlib can be used to create a line chart?

40
Summary
• Matplotlib is a comprehensive library for creating static, animated,
and interactive visualizations in Python.
• Matplotlib produces publication-quality figures in a variety of
hardcopy formats and interactive environments across platforms.
Matplotlib can be used in Python scripts, the Python and IPython
shell, web application servers, and various graphical user interface
toolkits.

41
References
• https://matplotlib.org/stable/tutorials/introductory/pyplot.html
• https://pypi.org/project/matplotlib/
• https://jakevdp.github.io/PythonDataScienceHandbook/04.00-introdu
ction-to-matplotlib.html

42
THANK YOU

For queries
Email: amandeep.ece@cumail.in

43

You might also like