New Tutorials:   TKINTER    KOTLIN    JAVASCRIPT    SASS/SCSS    PL/SQL    Matplotlib    C++ Programs
See the Tutorial List

Introduction to Matplotlib

In this tutorial, we will cover the basic introduction of the Matplotlib library in Python, important modules within Matplotlib, how to install Matplotlib module and we will understand how this library is useful for data visualization.

What is Matplotlib?

Matplotlib is basically a Multiplatform visualization library for data that is built on NumPy Arrays. This Library is designed to work with the broader SciPy stack, which includes different modules of Python used for machine learning and data science.

  • Matplotlib is the default(sort of) Python Data Visualization Package.

  • As Matplotlib is a visualization library, these visualizations allow us to represent huge amount of data in visual form like charts and plots.

  • Matplotlib is useful in creating 2D plots from the data in Arrays.

  • Matplotlib library is inspired by MATLAB programming language and it also provides a similar interface like MATLAB for graphics.

  • This library gets easily integrated with the Pandas package which is used for data manipulation.

  • With the combination of Pandas and Matplotlib data wrangling can be done along with the visualization and one can get valuable insights out of the data.

  • Matplotlib library in Python is mainly known as Grammer of Graphics and it is the most used library for creating charts and plots in Python.

  • Matplotlib can be used with Jupyter Notebook, web server Applications, and IPython shells.

It was written by John D. Hunter in 2003 and it was born with its 0.1 version. Matplotlib received an early boost at the time when it was adopted as the plotting package of choice by the Space Telescope Science Institute.

The current stable version is 2.2.0 and it was released in 2018.

Important Modules in Matplotlib

There are two important modules in Matplotlib Library and these are given below:

Matplotlib important modules - pyplot and pylab

1. pyplot

  • It is an important module in Matplotlib. In our further tutorials in code examples, you will often see matplotlib.pyplot being used.

  • This module mainly provides us an interface that allows us to automatically and implicitly create figures and their axes to achieve the desired plot.

  • This is a great module when you quickly want to plot something without the instantiation of any figure or any axes.

2. pylab

  • It is another important module of Matplotlib.

  • You need to install this module alongside the matplotlib module.

  • The Module pylab helps to import NumPy and pyplot and it is recommended when you need to work with arrays, perform mathematical operations, and you want to access the plotting features.

  • It is not recommended in case you are using IPython Kernel.

Installing Matplotlib

The dependent packages of Matplotlib and the matplotlib itself are available in the standard Python package repositories in the form of a wheel package. Thus it can be easily installed on MacOS, Window, Linux, etc. using the pip package manager.

Note: You must have Python installed on your machine, to install matplotlib module. Here is our Python Installation Guide.

You just need to open your command prompt write the following given command:

python -m pip install -U matplotlib

If you are using Jupyter Notebook, then it is important to note that Jupyter Notebook comes with many preinstalled libraries like Numpy, Pandas, Matplotlib, Scikit-Learn, so you don't have to worry about installing these modules/libraries separately.

Summary:

So in this tutorial, we learned what is matplotlib module, why it is so popular, the different modules of matplotlib which are useful and then we also learned how we can install the matplotlib module.