IMPLEMENTATION OF DATA VISUALIZATION LIBRARY
By: Mahesh Singh Dasila
Tags: Plotting Data, Seaborn, Matplotlib, Data Science, Data Visualization

Data visualization is nothing more but data analysis only through plots , graphs and by visualizing and comparing the data-points of the data-set .

So why Data visualization ?

See in a practical scenario as a human you must have observed that even during talking or speaking what we do is we first try to visualize things back in our mind so that we could have a better understanding of the things and then reply or revert back to it accordingly. So in this case also by visualizing data helps us to understand the data-set much better .

Also suppose our data-set size is very large, say 10 million entries then you can’t just sit and look for each and every entry , so here data visualization helps us a lot.

If we see the visualization in models then we will get to know about how the data-points are arranged. For example whether the data-points are scattered ,over-fitted , under-fitted ,we could see the exponential growth of the continuous values in data-set like linear regression. So we could remove the model which are not suitable accordingly and replace with the right one .This will save a lot of time.

So moving forward you should be aware that this data visualization through different libraries comes under the EDA i.e Exploratory Data Analysis.

Before moving forward let me tell you what all I will be covering in this article. Data — Visualization Library

1) Matplotlib

2) Seaborn

Ok so as you can see I will be discussing the majorly used matplotlib and seaborn library which are being used in our projects .I will be discussing it in detail so don’t worry .

MATPLOTLIB

Matplotlib is a data visualization library which convert the data-points in the data-set in a graphical representation such that showing the relationship between the attributes or parameters.

Also remember the attributes would be selected by you only depending upon the data-set , like you have to see what is my input column and what is my target column or if you just want to see the relationship between the two column.

Matplotlib is a 2D and 3D graphics library which gives a very excellent result with the numerical data.

Till now I think you must have understood that why data visualization is used and what is it. Now we will discuss what is the advantage of using matplotlib?

1) We can start with simple plots

2) it gives you the facility to change the labels and text in plots

3) high quality output in many format

Under matplotlib I will be covering these topics-

1) Matplolib import

2) Basic Matplotlib commands

3) Matplotlib object oriented method

i) Subplots()

ii) Figure size ,aspect ratio and dpi

iii) Saving figures

iv) Legends, labels and titles

1) Matplotlib import

We can import the matplotlib library by following this syntax-

import matplotlib.pyplot as plt

%matplotlib inline

In the first line I am importing the module as plt and in the second line if you are using jupyter notebook then to see plots in the notebook itself then you have to write that.

2) Basic Matplotlib commands

We can make the simple line plot as –

Here x and y are having some value and ‘r’ is for red color. Other than that we are just editing the text in the X-axis and Y-axis and also the title .Now I’ll show you its output then you will get clear.

3) Matplotlib object oriented method

The main motive behind using this object oriented method is that here we just create the instance and call the attributes and method through that instance or object. This is a good approach when we have to deal with multiple plot in one plots.

Here is the code -

As you can see a object fig is created and then its attribute add_axes is being called. See the output -

i) Subplots()

It acts as a automatic axis manager, we don’t have to mention the axis points when using subplots().

Now in the output same results will be shown.

ii ) Figure size and dpi

As you already know how we created the object “fig” earlier ,so figure size and dpi are just the arguments of it.

Figure size- is a tuple with width length and height length of the fig in inches.

Dpi –it is dots-per-inch or you can say pixels per inch .

See the example you’ll get clear.

Or you can just pass the ‘figsize’ in subplot().

See the output-

iii) Saving figures

You can save the file with savefig method in Figure class.

iii) Legends, labels and titles

As we have covered the basics now to make the plots more attractive and understandable we make use of legends. I have already discussed you the editing of labels and titles in x-axis and y-axis ,so I am skipping that.

Legend –it just shows you the labels of — what line or point represent to what attribute.

See the example-

Output-you can see the labels at the right top corner.

2) SEABORN

It is also an data visualization library and it is based on matplotlib. It basically provide us with the advance graphical representation of the plots.

They are in n number but here I am using few most used –

1) Joint plot

2) Dist plot

3) Box plot

4) Swarm plot

5) Count plot

6) Heat-map

7) Facet grid

1)Joint plot

In joint plot as you can see that we could get the relationship of any 2 particular column in the data-set and titanic here is the data-frame name.

2) Dist plot

Dist plot basically takes a single column in the dataset and it shows the distribution of the values or data-points . Here kde on making True it will just make the flow line above each data-point.

3)Box plot

Box plot is again one of the plot representation taken between two columns . Palette argument is showing the combination of colors.

4) Swarm plot

Swarm plot always gives the representation between two columns.

5)Count plot

Count plot shows the distribution of the column values with the total number of counts in it.

6) Heatmap

It is also one of the graphical representation where the values are contained in the matrix are represented with different colors.

7)Facet grid

Facet grid shows the different plots of the particular column having different values like in this case categorical value of ‘sex’ column is male and female.

That’s it from my side and if you like it don’t forget to clap.

-Mahesh Singh Dasila