Introduction to Matplotlib Library for Data Visualization

Introduction to Matplotlib Library for Data Visualization


Data Visualization is one of the most important tasks in data analysis to explore and communicate our data. It is so broad field that many books have been written so far by great publishers which you can find on book stores. In this article, we will try to introduce Matplotlib library which is widely used for data visualization in python as data science toolkit to create quality plots ready for publications.

Matplotlib is generally a two-dimensional (2D) MATLAB style plotting library of python, created by John D. Hunter in 2002. Since then, John D. Hunter also cooperated with Fernando Perez (Creator of IPython) and others to make IPython work with this Matplotlib library for scientific computing. This cross-platform supported library is built on NumPy library designed to work with SciPy stack library for scientific computations. 

This library first commercially released on 2003 can be used in Python and IPython shells, Python scripts, Jupiter notebooks, web-application servers and GUI toolkit. Matplotlib supports many different GUI backends and it can also export graphics to different output formats such as SVG, JPG, PNG, GIF, etc. Using Matplotlib library, you can create different types of plots i.e. histograms, power spectra, scatter plots, line plots, bar plots, error charts and others with few lines of programming.

Let’s demonstrate some points about how to use Matplotlib library to generate different types of plots.
For generating different types of plots you have to use matplotlib.pyplot module which contains all command functions of plotting by importing as shown in the following example with Jupiter Notebook Program. You will notice that we have used plt as an interface for using matplotlib.pyplot module to generate plots in this tutorial post.

In[1]: import matplotlib.pyplot as plt
       days = [1,2,3,4,5,6,7]
       temp = [10, 12, 11, 12, 11, 12, 13]

       # Create a line chart, using days on x-axis and temp on y-axis
       plt.plot(days,temp, marker='o', color='green')

       # For adding title you use title function with interface plt
       plt.title('Plotting Temperature VS each Date')

       # Adding Label names to x-axis and y-axis
       plt.xlabel('Date')
       plt.ylabel('Temperature in Celcius')

       # Show Plot on Screen
       plt.show()



Making plots of publications quality is more complex that it cannot be discussed in this single post of medium length. We will discuss in the next coming tutorials more about plotting pertaining creation of scatter plot, line plot and bar plots in the subsequent tutorials.




Comments