The Matplotlib Library

Africa Data School
4 min readFeb 12, 2021

Hello everyone! Today I want to write about the Matplotlib Library.

“An editorial approach to visualisation design requires us to take responsibility to filter out the noise from the signals, identifying the most valuable, most striking or most relevant dimensions of the subject matter in question.” — Andy Kirk

Introduction

The purpose of having to use the Matplotlib library is for visualisation. Visualisation is the formation of mental visual images. It is the act or process of interpreting in visual terms or of putting it into a visible form. It involves producing images that communicate the relationships among represented data to the viewers of the images. Matplotlib is specifically good for creating basic graphs like line charts, bar charts, histograms, etc. if you have worked with data before you are aware of the line.

Matplotlib is a plotting library for the Python programming language and its numerical mathematics extension NumPy. It provides an object-oriented API for embedding plots into applications using general-purpose GUI tool kits like Tkinter and GTK.

What is Matplotlib?

Matplotlib Library is a python based library that is used in the creation of static, animated, and interactive data visualizations. It is a platform that is used for making 2D plots from a data array. By providing an object-oriented API it enables the embedding plots in applications using the graphical user interface (GUI) tool-kits such as the PyQt.

Matplotlib uses the Pyplot interface which is similar to the Matlab Module. It allows one to generate interactive data visualizations such as two-dimensional diagrams and graphs (histograms, scatter-plots). Used in the visualization of data relationships. Matplotlib allows one to generate interactive data visualizations such as two-dimensional diagrams and graphs (histograms, scatter-plots). Used in the visualization of data relationships.

Let us plot a line plot using Matplotlib

In the picture below we import the matplotlib library using the,

import matplotlib. pyplot as plt.

An image that illustrates matplotlib in plotting a line

we also include another library the NumPy library,

import NumPy as np.

When working with data we use several methods that are used to help us understand the relationship in the data set. Matplotlib comes into play given it is a useful plotting tool. Below is an illustration of a relationship between random numbers by using s scatter plot.

A 3d plot using Matplotlib

3d presentation.

Matplotlib and Pyplot.

Matplotlib.Pyplot is a collection of commands that enable matplotlib to function similarly to Matlab. Pyplot functions are used to make changes to a figure that is by creating a plotting area, line plotting, or creating a figure. It is intended for the interactive plots and simple cases of programmatic plot generation.

Visualisation options in Matplotlib

Bar chart

These are rectangular blocks that are used to represent a data set. Bar charts are plotted in a way that they represent a value on one axis and the variable on the other axis. Bar charts are best suited to represent categorical data.

Histogram

This is a type of graph that is used to represent numerical data by indicating the number of data points within a range of values.

Line chart

This is a visualization technique that is used to represent a data set in the form of a line. Line charts are easy to understand and are used in the representation of data that changes over time.

Scatter plot

This is a data display type that uses dots to show the relationship between data points. Usually, the relationship is between two numeric variables where members of the data set are plotted on the x, y-axis that relates to the value of a numeric variable.

Toolkits used to extend the functionality of Matplotlib

  • Base Map
  • Cartopy
  • Seaborn
  • Numpy
  • Gtk tools
  • Exel tools

Conclusion

“By visualising information, we turn it into a landscape that you can explore with your eyes. A sort of information map. And when you’re lost in information, an information map is kind of useful.” — David McCandless

If you need to visualise the relationship between a data set be sure to use this library. Matplotlib offers a variety of visualisation options which are bar graphs, line graphs, 3D visualisation options, scatter plots, etc.

--

--

Africa Data School

Intensive training for a career in artificial intelligence and machine learning. https://africadataschool.com/