0% found this document useful (0 votes)
18 views22 pages

Mat Plot Lib

Uploaded by

Yoonji Min
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views22 pages

Mat Plot Lib

Uploaded by

Yoonji Min
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

INTRODUCTION TO

MATPLOTLIB
Submitted by:
Dilasha Rajkarnikar(ACE076BCT036)
Drishya Bhattarai(ACE076BCT037)
Bishal Manandhar(ACE076BCT032)
What is Matplotlib?

● Matplotlib is an open-source drawing library that supports various


drawing types.
● You can generate plots, histograms, bar charts, and other types of
charts with just a few lines of code
● It’s often used in web application servers, shells, and Python
scripts
Importing Matplotlib

● From matplotlib import pyplot as plt

OR

● Import matplotlib.pyplot as plt

It means we are importing the pyplot module of matplotlib into our namespace
as plt.
Pyplot
Pyplot is a Matplotlib module that provides simple functions for adding plot elements,
such as lines, images, text, etc. to the axes in the current figure.

All commands like plot() , scatter() etc reside in the pyplot module.
Let us take an example that uses Matplotlib.
The first array appears on the x-axis, and the second array appears on
the y-axis of the plot.
Titles and Labels
We can add a title, as well as the x-axis and y-axis names, using the following methods:

● title()
● xlabel()
● ylabel()

Let us take an example for titles .


Title: Info

Xlabel: X-axis

Ylabel: Y-axis
Figure size
Users can also specify the size of the figure using the figure() method.
Matplotlib subplots

You can use the subplot() method to add more than one plot in a figure.

Syntax: plt.subplots(nrows, ncols, index)

The three-integer arguments specify the number of rows and columns and
the index of the subplot grid.
Example:
add_subplot() function
The add_subplot() function of the figure class enables us to add a graph inside a
graph.
Important Types of Plot

● Bar graphs
● Histograms
● Scatter plots
Bar Graphs

A bar graph presents data with heights and lengths proportional to the
values they present.

Syntax: ax.bar(x, height, width, bottom, align)


Example:
Histogram

A histogram is a graphical representation of the distribution of data, also


used to understand the distribution of a continuous numerical variable.
It is a graph showing the number of observations within each given
interval.

Syntax: ax.hist(x, bins=number of bins)


Example:
Scatter Plots

Scatter plots are used to represent values


for two different numeric variables.
The scatter() function plots one dot for each
observation. It needs two arrays of the same
length, one for the values of the x-axis, and
one for values on the y-axis.
Syntax:
ax.scatter(x_axis_data,y_axis_data)
Example:
Output:
Matplotlib Three-Dimensional Plotting
● Importing the mplot3d toolkit enables users to create three-dimensional plots.

Importing: from mpl_toolkits import mplot3d

● Once this submodule is imported, a three-dimensional axes can be created by


passing the keyword projection='3d' to any of the normal axes creation
routines:
Axis Creation:

fig = plt.figure()

ax = plt.axes(projection='3d')
Example:
Thank You!

You might also like