Tutorial Playlist

Python Tutorial for Beginners


How to Install Python on Windows?

Lesson - 1

Python OOPs Concept: Here's What You Need to Know

Lesson - 2

Getting Started With Jupyter Network

Lesson - 3

PyCharm Tutorial: Getting Started with PyCharm

Lesson - 4

A Beginner’s Guide To Python Variables

Lesson - 5

Python Numbers: Integers, Floats, Complex Numbers

Lesson - 6

Learn A to Z About Python Functions

Lesson - 7

The Basics of Python Loops

Lesson - 8

Introduction to Python While Loop

Lesson - 9

Python For Loops Explained With Examples

Lesson - 10

Understanding Python If-Else Statement

Lesson - 11

Introduction to Python Strings

Lesson - 12

Everything You Need to Know About Python Slicing

Lesson - 13

All You Need To Know About Python List

Lesson - 14

Python Regular Expression (RegEX)

Lesson - 15

An Introduction to Python Threading

Lesson - 16

Objects and Classes in Python: Create, Modify and Delete

Lesson - 17

The Best Python Pandas Tutorial

Lesson - 18

A Beginner's Guide To Web Scraping With Python

Lesson - 19

A Handy Guide to Python Tuples

Lesson - 20

How to Easily Implement Python Sets and Dictionaries

Lesson - 21

Everything You Need to Know About Python Arrays

Lesson - 22

An Introduction to Matplotlib for Beginners

Lesson - 23

An Introduction to Scikit-Learn: Machine Learning in Python

Lesson - 24

Top 10 Python IDEs in 2020: Choosing The Best One

Lesson - 25

The Best NumPy Tutorial for Beginners

Lesson - 26

Python Django Tutorial: The Best Guide on Django Framework

Lesson - 27

Top 10 Reason Why You Should Learn Python

Lesson - 28

How To Become a Python Developer

Lesson - 29

Top 50 Python Interview Questions and Answers for 2020

Lesson - 30
An Introduction to Matplotlib for Beginners

To make necessary statistical inferences, it becomes essential to visualize your data, and Matplotlib is one such solution for Python users. It is a comprehensive plotting library useful for those working with Python and NumPy. In this Matplotlib tutorial, we will cover all the functionality of this module, including the following topics:

  • What is Matplotlib?
  • Getting started with pyplot
  • Matplotlib: subplots
  • Important types of plots
    • Bar charts
    • Histograms
    • Scatter plots
  • Matplotlib: three-dimensional plotting
  • Hands-on demo

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

Python Training Course

Learn Data Operations in PythonExplore Course
Python Training Course

Getting Started With 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.

Let's begin our tutorial with a simple graph that uses fundamental Matplotlib code in Jupyter Notebook. 


 Fig: Basic plot-matplotlib tutorial

Note that the first array appears on the x-axis, and the second array appears on the y-axis of the plot.

Let us now see how we can add a title, as well as the x-axis and y-axis names, using the title(), xlabel(), and ylabel() methods, respectively.


Fig: label()

Users can also specify the size of the figure using the figure() method. Additionally, users can pass values as tuples, which make up the length of rows and columns to the argument figsize.


Fig: figure() method-matplotlib tutorial

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.



Fig: subplot()

The add_subplot() function of the figure class enables us to add a graph inside a graph.


Fig: add_subplot()

Important Types of Plots

  • Bar graphs
  • Histograms
  • Scatter plots

1. 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)



Fig: Bar graph-matplotlib tutorial

The axes label is a region of the image with data space. 

An axes object is added to figure by the add_axes() method. The syntax for the axes object is: ax = fig.add_axes([left,right,width,height]).

2. Histograms

A histogram is used to understand the distribution of a continuous numerical variable.



Fig: Histogram

3. Scatter Plots

Scatter plots are used to represent values for two different numeric variables.


Fig: Scatter plot



Fig: Scatter plot

Matplotlib Three-Dimensional Plotting

Importing the mplot3d toolkit enables users to create three-dimensional plots. 



Fig: Three-dimensional plotting-matplotlib tutorial

Practice Example

For this practice drill, you’ll write a Python program that will create a pie chart showing the popularity of programming languages.



Fig: Solution

Autopct is used to display values on the pie slice.

Looking forward to make a move to programming? Take up the Python Training Course and begin your career as a professional Python programmer.


In this Matplotlib tutorial article, we discussed the basic concepts related to the Matplot library. We looked at how to create basic graphs and plots, and its different functions. We discussed three-dimensional plotting and sub-plots as well. 

If you have any other questions, please feel free to ask them in our comments section, and we'll get back to you as soon as possible.

Want to Learn More About Python?

Python is one of the most widely used programming languages in the fields of data science and analytics. That means there’s a high demand for qualified professionals. If you’re ready to boost your career in these exciting fields, check out our Python Training Course today!

About the Author

Aryan GuptaAryan Gupta

Aryan is a tech enthusiast who likes to stay updated about trending technologies of today. He is passionate about all things technology, a keen researcher, and writes to inspire. Aside from technology, he is an active football player and a keen enthusiast of the game.

View More
  • Disclaimer
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, and OPM3 are registered marks of the Project Management Institute, Inc.