What is Data Visualization?
• As we know it is an era of Big Data,
• And this Data is very important for any organization
for decision making.
• Visualization techniques of such big data are very
important for the purpose of analysis of data.
• “Data Visualization basically refers to the graphical or
visual representation of data using visual elements
like chart, graph and map etc.
Data Visualization
“Data Visualization basically refers to the graphical or
visual representation of information and data using
visual elements like charts, graphs or maps.
• In this chapter we will come to know about Pyplot in
Python.
• We will also come to know about the visualization of
data using Pyplot.
Use of Pyplot of MATPLOTLIB Library
• The Matplotlib is a python library that provides many
interfaces and functionality for 2D-graphics similar to
MATLAB.
• We can call it as high quality ploting library of
python.
• Matplotlib library offers many different named
collections of methods; Pyplot is one such interface.
• Pyplot is a collection of methods within matplotlib
which allow us to construct 2D plots easily and
interactively.
Installing and importing Matplotlib
Importing Pyplot
• Following syntax need to write to import Pyplot
import [Link]
OR
import [Link] as pl
• We will use commands afterwards using pl with
(.).
• Before proceeding we need to know something
about numpy.
• Numpy provides very useful functions for ploting.
• Numpy also supports vectorized functions.
NumPy Arrays
• NumPy (“Numerical Python” or Numeric Python”) is an open source
module of Python which provides functions for arrays and matrices.
• NumPy is needed to import for its use. The statements for the same is
as follows-
>>>import numpy as np
(np is another name for numpy which is optional.
• NumPy arrays is of two types-
• 1-D array – also known as Vectors.
• Multidimentional arrays –
also known as Matrices.
See the
difference
between List
and array
Basics of Simple Plotting
• Graphical representation of compiled data is known
as data visualization.
• Chart and Graph are very important tools for data
visualization.
• Pyplot can be used for developing various types of
graphs and charts.
• We will go through following charts in syllabus-
– Line chart
– Bar Chart
– Scatter Plot
Creating Line Chart
• A line chart or line graph is a type of chart which
displays information as a series of data points called
‘markers’ connected by a straight line segments.
• The pyplot interface offers plot() function for creating
a line graph. -
Creating Line Chart
• Let’s take an example – here we have data of runs made in 5
overs. We will name X axis as overs and Y axis as runs.
We will use these
functions for labeling.
Labels are shown in
resultant chart.
Setting of Line color, width and style
• It has following syntax -
[Link](<data1>,<data2>,<color code>)
‘r’ is used for Red color
and ‘b’ is used for blue
color.
Both the
colors are
shown in
resultant
chart.
Changing Line color, width and style
• It has following syntax -
[Link](<data1>,<data2>,linewidth=<val>…)
Use ‘:’ , ‘-’ , ‘--’ ,
‘-.‘ for different line
styles.
Changing Marker type, size and color
-It has following syntax -
[Link](<data1>,<data2>,linestyle=<val>…)
[Link]
[Link] A use full Link to understand pyplot
Creating Scatter Chart
• Scatter chart is a graph of plotted points on two axes that
shows the relationship between two sets of data.
• There is 2 methods of creating scatter chart.
– From plot( ) function.
– From scatter( ) function.
• Syntax of plot() function is-
[Link](a,b,<point style >, markersize=<value>)
Creating Scatter Chart
• Syntax of scatter () function is –
[Link](a, b, marker=<type>)
• Changing Line color-
Creating Bar Chart
• A Bar Graph /Chart a graphical display of data using bars of
different heights. Syntax is– [Link](a,b)
These functions are used
for labeling.
Labels are shown in
resultant chart.
Changing Bar width
• A Bar Graph /Chart a graphical display of data using bars of
different heights. Syntax is–
[Link](a, b, width=<Value>)
It is also possible to set the different width of bars
for different data.
Changing Bar color
• A Bar Graph /Chart a graphical display of data using bars of
different heights. Syntax is–
[Link](a, b, color=<code>)
Creating Multiple Bar Chart
The fact to notice here is that the number
of times you use bar () function before
calling Show() Function, it will be added to
the same chart.
Creating Horrizontal Bar Chart
barh() function is being used here.
Anatomy of Chart
• Chart has a structure. See the following points-
• Figure – Any chart will be made under this area only. This
is the area of plot.
• Axes – This is that area which has actual ploting.
– Axis Label – This is made up of x-axis and y-axis.
– Limits – This is the limit of values marked on x-axis and y-axis.
– Tick Marks – This is the individual value on x-axis and y-axis.
• Title – It is the text to be shown at the top of plot.
• Legends – This is the set of data of different color which is
to be used during plotting.
Adding Title and setting xlimit & ylimit
[Link] () and [Link] () functions are used
here.
Adding Legends
Legends Legends
Saving a Figure
This line will be written to
save the figure of Plotting.