LAST UPDATED: SEPTEMBER 6, 2020
Matplotlib PyPlot API
In this tutorial, we will cover the Pyplot API in Matplotlib in detail, helping you understand the use of Pyplot API in Matplotlib.
The matplotlib.pyplot
is basically the collection of command style functions that helps in making the Matplotlib work like MATLAB.
-
pyplot
is mainly intended in Matplotlib for making interactive plots and simple cases of programmatic plot generation.
-
Each function in pyplot makes some changes to the figure, for example, there is a function to create a figure, for creating a plotting area in a figure, for plotting some lines in the plotting area, for decorating the plot with labels, etc.
New Notebook in Jupyter Notebook
If you want to create a new notebook in Jupyter notebook where you desire to store your work then we have shown you the option in our previous tutorial. Now when you click on the "New" button then there you have options like Python3, terminal, folder, etc.
Just click on Python3 and then there is a python Notebook for you that will be saved with (.ipynb
) extension.
Let us show you an image then it becomes clear to you:
Now in this notebook, you can run your commands, can draw any kind of plot, histogram, or anything you want using Matplotlib, run it, and then save it.
Different type of Plots
Let us now discuss different types of plots that can be visualized with the help of Matplotlib library:
-
Bar
This will create a Bar plot.
-
hist
This will create a histogram.
-
hist2D
This will create a 2-dimensional histogram.
-
Pie
This will create a Pie chart.
-
Boxplot
This will create a Box and whisker plot.
-
Plot
This will help to plot lines.
-
Scatter
This will be used to draw a scatter plot of x
vs. y
.
-
Stackplot
This is used to draw a stacked area plot.
-
Quiver
This will help to plot a 2-dimensional field of arrows.
-
Stem
This will draw a stem plot.
-
Polar
This will draw a polar plot.
-
Step
This will draw a stem plot.
Different type of Figure Functions
Let us discuss some functions related to figures in Matplotlib and these are given below:
-
figure
This will create a new figure.
-
figtext
This is used to add text to the figure.
-
savefig
This is used to save the current figure.
-
show
This is used to display the figure.
-
close
This is used to close the window of the figure.
Different type of Image Functions
Let us discuss some functions related to images in Matplotlib:
-
Imread
This function is used to read an image from a file into an array
-
Imsave
This function is used to save an array in an image file.
-
Imshow
This is used to display the image on the axes.
Different types of Axis Functions
let us discuss some functions related to the axis in Matplotlib:
-
Axes
This is used to add axes to the figure.
-
Text
This is used to add the text to the Axes.
-
Title
This is used to set a title of the current axes
-
XLabel
This is used to Set the x-axis label of the current axis
-
YLabel
This is used to Set the y-axis label of the current axis
-
XTicks
This is used either to Get or set the x-limits of the current tick locations and labels.
-
YTicks
This is used either to Get or set the y-limits of the current tick locations and labels.
-
XScale
This is used to set the scaling of the x-axis.
-
YScale
This is used to set the scaling of the y-axis.
-
XLim
This is used to either Get or set the x-limits of the current axes
-
YLim
This is used to either Get or set the y-limits of the current axes
Summary:
In this tutorial, we covered the various useful functions and properties of the Pyplot API in Matplotlib library.