Data analytics subject, Slides of Computer science

Python libraries includes pandas, matplotlib, seaborn.

Typology: Slides

2025/2026

Available from 06/30/2026

poojitha-chougani
poojitha-chougani 🇮🇳

8 documents

1 / 32

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PYTHON-MATPLOTLIB
UNIT-I
Department of CSE, School of Engineering, Malla Reddy
University, Hyderabad.
MATPLOTLIB UNIT-1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20

Partial preview of the text

Download Data analytics subject and more Slides Computer science in PDF only on Docsity!

PYTHON-MATPLOTLIB

UNIT-I

Department of CSE, School of Engineering, Malla Reddy

Q1: Introduction to Matplotlib :

Middle Level

Language

Structured

Language

Rich

Library

Extensible

Recursion

Pointers

Speed

Memory

Management

Department of CSE, School of Engineering, Malla Reddy

Matplotlib is the most popular multi-platform MATPLOTLIB library for

python which gives control over every aspect of a figure. It was

designed to give the end user a similar feeling like MATLAB‟s.

The multidimensional MATPLOTLIB built on NumPy arrays

Installation:

Matplotlib and its dependency packages are installed , when we install

the Matplotlib by using following pip command.

matplotlib.pyplot is a collection of command style functions.

Each pyplot function makes some change to a figure. For example, a

function creates a figure, a plotting area in a figure, plots some lines

in a plotting area, decorates the plot with labels, etc.

pip install matplotlib

Middle Level

Language

Structured

Language

Rich

Library

Extensible

Recursion

Pointers

Speed

Memory

Management

Another one of the most important sections on this page is

gallery section

It shows all the kind of plots/figures that Matplotlib is capable of

creating for you. You can select anyone of those, and it takes you the

example page having the figure and very well documented code.

Another important page is

https://matplotlib.org/stable/api/pyplot_summary.html

It shows the documentation functions in it.

https://matplotlib.org/gallery.html

Department of CSE, School of Engineering, Malla Reddy

Middle Level

Language

Structured

Language

Rich

Library

Extensible

Recursion

Pointers

Speed

Memory

Management

1: Basic Plots using Matplotlib

1. Area Plots or area chart

  1. Line plots
    1. Bar plots or Bar charts
    2. Histograms 2. Specialized Visualization Tools using Matplotlib
    3. Pie charts
    4. Box plots
    5. Scatter Plots
    6. Bubble plots

3: Advanced Visualization Tools using Matplotlib

  1. Waffle Charts
  2. Word Clouds

Department of CSE, School of Engineering, Malla Reddy

Middle Level

Language

Structured

Language

Rich

Library

Extensible

Recursion

Pointers

Speed

Memory

Management

Example 1: to draw the area plot by using fill_between()

function.

Department of CSE, School of Engineering, Malla Reddy

import matplotlib.pyplot as

plt

# Create data

x=[1,2,3,4,6]

y=[1,4,5,8,4]

# Area plot

plt.fill_between(x, y)

plt.show()

Middle Level

Language

Structured

Language

Rich

Library

Extensible

Recursion

Pointers

Speed

Memory

Management

Example 1: to draw the area plot by using stackplot() function.

Department of CSE, School of Engineering, Malla Reddy

import matplotlib.pyplot as

plt

# Create data

# x=range(1,6)

x=[1,2,3,4,5]

y=[1,4,5,8,5]

# Area plot

plt.stackplot(x,y)

plt.show()

Output:

Middle Level

Language

Structured

Language

Rich

Library

Extensible

Recursion

Pointers

Speed

Memory

Management

Example 1: to draw the line plot without labels by using plot()

function.

Department of CSE, School of Engineering, Malla Reddy

import matplotlib.pyplot

as plt

plt. plot ([1, 2, 3], [4, 5,

1])

plt.show ()

Middle Level

Language

Structured

Language

Rich

Library

Extensible

Recursion

Pointers

Speed

Memory

Management

Department of CSE, School of Engineering, Malla Reddy

PYTHON PROGRAMMING UNIT-

x=[1,2,4,8,9]

y=[1,3,6,6,4]

plt.plot(x,y)

plt.title('sample line graph')

plt.xlabel('x values')

plt.ylabel('y values')

plt.show()

Example 2: to draw the line plot with labels by using plot()

function.

Middle Level

Language

Structured

Language

Rich

Library

Extensible

Recursion

Pointers

Speed

Memory

Management

Example 4 :

import matplotlib.pyplot as plt

plt. plot ([1, 2, 3], [4, 5, 1],label="plot one",linewidth=7)

plt. plot ([1, 5, 3], [4, 5, 6],label="plot two",linewidth=3)

plt.title('sample line graph')

plt.xlabel('x values')

plt.ylabel('y values')

plt.grid(True)

plt.legend()

plt.show ()

plt.show ()

Department of CSE, School of Engineering, Malla Reddy

ormatting the style of the plot:

Middle Level

Language

Structured

Language

Rich

Library

Extensible

Recursion

Pointers

Speed

Memory

Management

3. Bar Plot (or) Bar chart:

Department of CSE, School of Engineering, Malla Reddy

A bar plot is a way of representing data where the length of the bars

represents the magnitude/size of the feature/variable. Bar graphs

usually represent numerical and categorical variables grouped in intervals.

The matplotlib API in Python provides the bar() function which can be

used in MATLAB style use or as an object-oriented API. The syntax of the

bar() function to be used with the axes is as follows:-

plt.bar(x, y, width, bottom, align)

The function creates a bar plot bounded with a rectangle depending on

the given parameters.

Middle Level

Language

Structured

Language

Rich

Library

Extensible

Recursion

Pointers

Speed

Memory

Management

Department of CSE, School of Engineering, Malla Reddy

import matplotlib.pyplot as plt

plt.bar([1, 2, 3], [4, 5, 1],label="plot one")

plt.bar([1, 5, 3], [4, 5, 6],label="plot two") #color=g

plt.title('sample line graph')

plt.xlabel('x values')

plt.ylabel('y values')

plt.grid(True)

plt.legend()

plt.show ()

Example 2: to draw the bar plot:

Middle Level

Language

Structured

Language

Rich

Library

Extensible

Recursion

Pointers

Speed

Memory

Management

Department of CSE, School of Engineering, Malla Reddy

i mport numpy as np

import matplotlib.pyplot as plt

creating the dataset by using dictionary

data = {'C':20, 'C++':15,

'Java':30,'Python':35}

courses = list(data.keys())

values = list(data.values())

creating the bar plot

plt.bar(courses, values, color ='maroon‘,

width = 0.4)

plt.xlabel("Courses offered")

plt.ylabel("No. of students enrolled")

plt.title("Students enrolled in different

courses")

Example 2: to draw the bar plot:

Middle Level

Language

Structured

Language

Rich

Library

Extensible

Recursion

Pointers

Speed

Memory

Management

Department of CSE, School of Engineering, Malla Reddy

from matplotlib import pyplot as plt

population_age =

[21,53,49,25,27,30,45]

bins = [0,10,20,30,40,50,60]

plt.hist(population_age, bins)

plt.xlabel('age groups')

plt.ylabel('Number of people')

plt.title('Histogram')

plt.show()

Output:

Example 1: to draw the Histogram:

Middle Level

Language

Structured

Language

Rich

Library

Extensible

Recursion

Pointers

Speed

Memory

Management

1. Pie Chart:

Department of CSE, School of Engineering, Malla Reddy

The “ pie chart” is also known as

“circle chart”, in which a circle is

divided into sectors that each

sector shows percentages of a

whole.

In Matplotlib, we use the pie()

function to create piechart

Pie chart image Example: