Data Visualization Python Tutorial using Matplotlib

Hi friends, welcome to Data Visualization Python Tutorial. So in this post we will learn an important topic of data science that is Data Visualization. Data visualization is the study to visualize data. So let’s start learning how to visualize data in python.

So we are going to analyze lot’s and lot’s of data, and everywhere whatever information we take, the data is going to be in the huge volume. Therefore it’s not easy  to analyze data in the form of numbers. Here comes the need of data visualization.

Data Visualization 


  • Data visualization is the process of converting raw data into easily understandable pictorial representation, that enables fast and effective decisions.
  • It is both an Art and a Science.
  • Data visualization is a strategy where we represent the quantitative information in a graphical form.

Why Data Visualization?

Now the question is that why we visualize data? So, the answer is that the pictorial form of data is easily understandable rather than huge numbers of numerical data.

You might heard that “A picture is worth a thousand words” ,as a result data visualization is so important.Therefore the key points are –

  • Data visualization is the first step of analysis work.
  • It gives intuitive understanding of data.
  • Helps you to see data in certain meaningful patterns.
  • Visual representations enhances the human cognitive process.
Data Visualization Python Tutorial
Data Visualization Python Tutorial
Data Visualization Python Tutorial
Data Visualization Python Tutorial

Let’s take an example, we see in  the above two pictures, first we have data in the numerical form and then next is pictorial representation of data.

So, now let me know that whether it is easy to analyze the numbers or visualization, definitely the visualization. Human brain works faster when we see a picture rather  than data, so that is the main concept we go for data visualization.

Benefits of Data Visualization

  • Data visualization allow users to see several different perspectives of data.
  • Data visualization makes it possible to interpret vast amounts of data.
  • It offers  ability to note expectations in data.
  • Exploring trends within a database through visualization by letting analysts navigate through data and visually orient themselves to the patterns in the data.

Data Visualization Techniques

Some of the popular techniques are:

  • Pie chart
  • Bar graph
  • Histogram
  • Wordle or tag cloud
  • Tree map
  • Scatter plot
  • Line chart
  • Bubble chart etc.

Data Visualization Python Tutorial

Python provides many libraries for data visualization like matplotlib, seaborn, ggplot, Bokeh etc.Here i am using the most popular matplotlib library.So let’s a look on matplotlib.


  • Matplotlib library is a graph plotting library of python.
  • Using matplotlib we can plot different scatter plots, line graphs, bar graphs, pie chart and histograms .
  • Using these plots we can visualize our data.
  • It provides an object-oriented APIs for embedding plots into applications using general-purpose GUI toolkits like Tkinter, wxPython, Qt, or GTK+.

Installing Matplotlib

Run the following command for installing matplotlib  –

Installing Pandas

Python has long been great for data munging and preparation, but less so for data analysis and modeling. Pandas helps fill this gap, enabling you to carry out your entire data analysis workflow in Python without having to switch to a more domain specific language like R.

Creating different visualizations

We can create different types of visualization using matplotlib.Now learn them one by one.

#1 Scatter Plot

First of all we create a scatter plot.Here we are using pyplot .Pyplot provides the state-machine interface to the underlying plotting library in matplotlib. This means that figures and axes are implicitly and automatically created to achieve the desired plot

The output of code will be as below

Data Visualization Python Tutorial
Data Visualization Python Tutorial


Finally that is looking pretty cool. Now if we want to include line graph into this we just have to  add two line in the above code.

So the output will be

Data Visualization Python Tutorial
Data Visualization Python Tutorial


#2 Bar Graph

Now we will discuss about bar graph.The code will be similar as scatter plot with a little change

Hence the output will be as –

Data Visualization Python Tutorial
Data Visualization Python Tutorial

Wow the bar graph is looking so much amazing.

#3 Pie Charts

Now let’s learn about pie charts.Pie charts can be drawn using the function pie() in the pyplot module. The below python code example draws a pie chart using the pie()function.

Let’s assume we gonna see how many students got 9 points and how many students got 8 points,7 points and so on.Pie chart will be the best option to visualize these kinds of data.

The output will be as shown below –

Data Visualization Python Tutorial
Data Visualization Python Tutorial

#4 Histogram

Now we will discuss about histogram.It is an estimate of the probability distribution of a continuous variable (quantitative variable) and was first introduced by Karl Pearson. It is a kind of bar graph.

Here i am taking an example of age distribution in a particular place.

So the output of the above code is –

Data Visualization Python Tutorial
Data Visualization Python Tutorial

#5 3D Plane wire frame Graph Chart

wire-frame graph chart is a visual presentation of a 3-dimensional (3D) or physical object used in 3D computer graphics.plot_wireframe() method is used to plot a wire frame.So, the code is as follows –

And the output of this code is

Data Visualization Python Tutorial
Data Visualization Python Tutorial

#6 3D Bar Plots

3D bar  draws a three-dimensional bar graph.

The above code will give this output

Data Visualization Python Tutorial
Data Visualization Python Tutorial

This is looking very nice.

So this is all about the Data Visualization Python Tutorial. If you have any doubt then comment. And please share this post with your friends if you think it is useful. Thank You 🙂

5 thoughts on “Data Visualization Python Tutorial using Matplotlib”

Leave a Comment