0% found this document useful (0 votes)
10 views68 pages

Python Programming: Matplotlib Basics

data analysis notes for Mca in artificial intigence and machine learning of chandigarh university e
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views68 pages

Python Programming: Matplotlib Basics

data analysis notes for Mca in artificial intigence and machine learning of chandigarh university e
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Academic Session 2025-26

ODD Semester Jul-Dec 2025

UNIVERSITY INSTITUTE OF COMPUTING


MCA DEPARTMENT
MCA/MCA(AIML)/MCA(CLOUD COMPUTING)/MCA(DATASCIENCE)
SEMESTER-1ST
PYTHON PROGERAMMING
(25CAH-606)
Unit [Link]
Topic : Python with matplot li

Mr. Ajay Yadav

Assistant Professor
1

Learning Objectives-
•Understand the Purpose of Matplotlib
Learn how Matplotlib helps in creating static, animated, and interactive visualizations in
Python.
•Familiarize with Matplotlib Components
Identify and understand key components such as Figure, Axes, Labels, Legends, and
Ticks.
•Create Basic Plot Types
Gain the ability to create various plots such as line plots, bar charts, histograms, scatter
plots, and pie charts.
•Customize Plots for Better Visualization
Learn how to enhance visualizations by modifying plot titles, axis labels, colors, markers,
and styles.
Syllabus

Unit-II
Introduction to Data Analytics, requirements of data analytics in Python.
Introduction to Numpy, features, environment setup, numpy Ndarray, array creation
data types, array attributes, numpy operations, mathematical and statistical
functions

Introduction to matplotlib, Figure class, Axes class, line plot, subplots, Bar plot,
histogram, scatter plot, pie chart, box plot, area chart, word cloud, Bee swarm plot,
violin graph, working with text, Customizing Plots: Titles, labels, and legends.

3
Matplotlib
• Matplotlib is one of the most popular Python packages used for data visualization.
• It is a cross-platform library for making 2D plots from data in arrays.

• Matplotlib is open source and use it freely.


• Matplotlib is mostly written in python, a few segments are written in C,
Objective-C and Javascript for Platform compatibility.
• Matplotlib has a procedural interface named the Pylab, which is designed to
resemble MATLAB, a proprietary programming language developed by
MathWorks. Matplotlib along with NumPy can be considered as the open source
equivalent of MATLAB.

4
Matplotlib
• Matplotlib Pyplot

5
Matplotlib
• Plotting Without Line

6
Matplotlib

7
Matplotlib
• Default X-Points :If we do not specify the points in the x-axis, they will get the
default values 0, 1, 2, 3, (etc. depending on the length of the y-points).

8
Matplotlib
• Line Properties: There are the following line properties:
• linestyle
• Color
• linewidth
• marker
• ms(marker size)
• mfc(marker color)
• title
• xlabel
• ylabel
• grid 9
Matplotlib
• Linestyle

10
Matplotlib
• Matplotlib Labels and Title

11
Matplotlib
• Add Grid Lines to a Plot

12
Matplotlib
• Display Multiple Plots: The subplot() function takes three arguments that
describes the layout of the figure. The layout is organized in rows and columns,
which are represented by the first and second argument. The third argument
represents the index of the current plot.

13
Matplotlib
• Python Matplotlib : Types of Plots

14
Matplotlib
• Types of Plots:
• Bar Graph: A bar graph uses bars to compare data among different categories. It
is well suited when you want to measure the changes over a period of time. It can
be represented horizontally or vertically.
• Histograms: Histograms are used to show a distribution whereas a bar chart is
used to compare different entities. Histograms are useful where arrays in very
large size.
• Scatter Plot : Usually scatter plots is used to compare variables, for example,
how much one variable is affected by another variable to build a relation out of it.
The data is displayed as a collection of points, each having the value of one
variable which determines the position on the horizontal axis and the value of
other variable determines the position on the vertical axis.
15
Matplotlib
• Area Plot : Area plots are pretty much similar to the line plot. They are also
known as stack plots. These plots can be used to track changes over time for two
or more related groups that make up one whole category.
• Pie Chart: A pie chart refers to a circular graph which is broken down into
segments i.e. slices of pie. It is basically used to show the percentage or
proportional data where each slice of pie represents a category.

16
Matplotlib
• Matplotlib Scatter

17
Matplotlib
• Matplotlib Bars

18
Matplotlib
• Matplotlib Histograms

19
Matplotlib
• Matplotlib Pie Charts

20
Matplotlib
• Matplotlib Area plot

21
Contents
• Numpy- Numerical operations on Numpy
• Plotting data from Numpy
• Matplotlib- Plotting a simple line graph
• Random walks, rolling dice with plotly
• Pandas-Data frame, key operations on data frame
• Plotting data from pandas data frame
• Visualizing repositories using plotly

22
Libraries in Python
• Python library is a collection of codes and methods that allow to perform many
actions without writing code.
• There are following different types of libraries in Python:
• Numpy ( Numerical Computing)
• Matlotlib (Data visualization)
• Pandas (Data manuplation)

23
NumPy
• NumPy is a Python package.
• It stands for 'Numerical Python’.
• It is a library consisting of multidimensional array objects and a collection of
routines for processing of array.
• It also has functions for working in domain of linear algebra, fourier transform,
and matrices.
• NumPy is a Python library and is written partially in Python, but most of the parts
that require fast computation are written in C or C++.

24
NumPy
• Examples:

25
NumPy
• Initializing NumPy Array with zeros:

26
NumPy
• Initializing NumPy Array with same number:

27
NumPy
• Initializing NumPy Array with a range method:

28
NumPy
• NumPy Array Indexing

29
NumPy
• NumPy Array Slicing

30
NumPy
• Data Types in NumPy:

31
NumPy
• Initializing NumPy Array with a shape method:

32
NumPy
• Initializing NumPy Array with a reshape method:

33
NumPy
• Iterating Arrays

34
NumPy
• Joining NumPy Arrays:

35
NumPy
• Addition of NumPy Arrays:

36
NumPy
• Addition of NumPy Arrays:

37
NumPy
• NumPy Math Functions:

38
NumPy
• Splitting NumPy Arrays:

39
NumPy
• Searching and Sorting NumPy Arrays:

40
NumPy
• NumPy Filter Array:

41
NumPy
• Random Numbers in NumPy:

42
NumPy
• Random Numbers in NumPy:

43
NumPy
• Python NumPy Array v/s List:
• NumPy array used instead of a list because of the below three reasons:
• Less Memory
• Fast
• Convenient

44
NumPy
• Less Memory

The above output shows that the memory allocated by list (denoted by S) is 28000 whereas the
memory allocated by the NumPy array is just 4000. This is a major difference between the two and
this makes Python NumPy array as the preferred choice over list.

45
NumPy
• Fast and Convenient:

List took 983ms whereas the numpy array took almost 56ms. Hence, numpy array is faster than list. Now,
a ‘for’ loop is used for a list to find sum, whereas for numpy arrays, added the two array by simply
printing A1+A2. That’s why working with numpy is much easier and convenient than lists.

46
Matplotlib
• Matplotlib is one of the most popular Python packages used for data visualization.
• It is a cross-platform library for making 2D plots from data in arrays.

• Matplotlib is open source and use it freely.


• Matplotlib is mostly written in python, a few segments are written in C,
Objective-C and Javascript for Platform compatibility.
• Matplotlib has a procedural interface named the Pylab, which is designed to
resemble MATLAB, a proprietary programming language developed by
MathWorks. Matplotlib along with NumPy can be considered as the open source
equivalent of MATLAB.

47
Matplotlib
• Matplotlib Pyplot

48
Matplotlib
• Plotting Without Line

49
Matplotlib

50
Matplotlib
• Default X-Points :If we do not specify the points in the x-axis, they will get the
default values 0, 1, 2, 3, (etc. depending on the length of the y-points).

51
Matplotlib
• Line Properties: There are the following line properties:
• linestyle
• Color
• linewidth
• marker
• ms(marker size)
• mfc(marker color)
• title
• xlabel
• ylabel
• grid 52
Matplotlib
• Linestyle

53
Matplotlib
• Matplotlib Labels and Title

54
Matplotlib
• Add Grid Lines to a Plot

55
Matplotlib
• Display Multiple Plots: The subplot() function takes three arguments that
describes the layout of the figure. The layout is organized in rows and columns,
which are represented by the first and second argument. The third argument
represents the index of the current plot.

56
Matplotlib
• Python Matplotlib : Types of Plots

57
Matplotlib
• Types of Plots:
• Bar Graph: A bar graph uses bars to compare data among different categories. It
is well suited when you want to measure the changes over a period of time. It can
be represented horizontally or vertically.
• Histograms: Histograms are used to show a distribution whereas a bar chart is
used to compare different entities. Histograms are useful where arrays in very
large size.
• Scatter Plot : Usually scatter plots is used to compare variables, for example,
how much one variable is affected by another variable to build a relation out of it.
The data is displayed as a collection of points, each having the value of one
variable which determines the position on the horizontal axis and the value of
other variable determines the position on the vertical axis.
58
Matplotlib
• Area Plot : Area plots are pretty much similar to the line plot. They are also
known as stack plots. These plots can be used to track changes over time for two
or more related groups that make up one whole category.
• Pie Chart: A pie chart refers to a circular graph which is broken down into
segments i.e. slices of pie. It is basically used to show the percentage or
proportional data where each slice of pie represents a category.

59
Matplotlib
• Matplotlib Scatter

60
Matplotlib
• Matplotlib Bars

61
Matplotlib
• Matplotlib Histograms

62
Matplotlib
• Matplotlib Pie Charts

63
Summary-
•Matplotlib is a powerful Python library for creating static, interactive, and animated visualizations in 2D (and basic
3D).
•It provides an easy-to-use pyplot interface (similar to MATLAB) for quick plotting, along with an object-oriented
API for advanced customizations.
•The Figure is the overall container, and Axes are the areas where plots like line charts, bar graphs, histograms,
etc., are drawn.
•Matplotlib supports a wide range of plots including line plots, bar charts, histograms, scatter plots, pie charts,
and box plots.
•It offers rich customization options for titles, labels, legends, colors, grids, styles, and also integrates well with
NumPy and Pandas.
Quiz /Questions-
1. What is Matplotlib and why is it used in Python programming?
(Explain its purpose and features.)
2. Differentiate between Figure and Axes in Matplotlib.
(Test understanding of object structure.)
3. Write a code to plot a simple line graph with labels for X and Y axes and a
title.
(Basic usage of [Link]() and formatting functions.)
4. What is the use of [Link]() and how does it differ from [Link]()?
(Test knowledge of subplots creation.)
5. Name and explain any three types of plots supported by Matplotlib.
(Like bar plot, histogram, scatter plot, etc.)
Class Wise Feedback
9

References/ Articles/ Videos


[Link]://[Link]/about/gettingstarted/
2. [Link]
3. [Link]
4. [Link]
5. [Link]
6. [Link]
7. [Link]
8. [Link]
9. [Link]
THANK YOU

68

You might also like