Signup/Sign In
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:

using Pyplot API in Matplotlib

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:

  1. Bar
    This will create a Bar plot.

  2. hist
    This will create a histogram.

  3. hist2D
    This will create a 2-dimensional histogram.

  4. Pie
    This will create a Pie chart.

  5. Boxplot
    This will create a Box and whisker plot.

  6. Plot
    This will help to plot lines.

  7. Scatter
    This will be used to draw a scatter plot of x vs. y.

  8. Stackplot
    This is used to draw a stacked area plot.

  9. Quiver
    This will help to plot a 2-dimensional field of arrows.

  10. Stem
    This will draw a stem plot.

  11. Polar
    This will draw a polar plot.

  12. 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:

  1. figure
    This will create a new figure.

  2. figtext
    This is used to add text to the figure.

  3. savefig
    This is used to save the current figure.

  4. show
    This is used to display the figure.

  5. 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.



About the author:
Aspiring Software developer working as a content writer. I like computer related subjects like Computer Networks, Operating system, CAO, Database, and I am also learning Python.