Data Visualization
-Python
What is data visualization?
Data visualization isthe representation of data through use of common
●
graphics, such as charts, plots, infographics, and even animations.
These visual displays of information communicate complex data relationships
●
and data-driven insights in a way that is easy to understand.
It allows us to quickly interpret the data and adjust different variables to
●
see effects.
Data visualization is a critical step in the data science process, helping teams
●
and individuals convey data more effectively to colleagues and decision makers.
●Teams that manage reporting systems typically leverage defined template
views to monitor performance.
What is Matplotlib?
Matplotlib is a python package used for 2D graphics.
●
●Matplotlib is a low level graph plotting library in python that
serves as a visualization utility.
Matplotlib was created by John D. Hunter.
●
Matplotlib is open source and we can use it freely.
●
●Matplotlib is mostly written in python, a few segments are written
in C, Objective-C and Javascriptfor Platform compatibility.
Plotting x and y points:
● The plot()function is used to draw points (markers) in a diagram.
● By default, the plot()function draws a line from point to point.
● The function takes parameters for specifying points in the diagram.
● Parameter 1 is an array containing the points on the x-axis.
● Parameter 2 is an array containing the points on the y-axis.
If we need to plot a line from (1, 3) to (8, 10), we have to pass two
●
arrays [1, 8] and [3, 10] to the plot function.
Types of plots:
PIE CHART
●
LINE GRAPH
●
HISTOGRAM or BAR GRAPH
●
SCATTER PLOT
●
Pie Charts
Line Chart
Histogram or Bar Graph
Scatter Plot
LINE GRAPH:
from matplotlib import pyplot as plt
[Link]([5,3,1],[2,7,1])
[Link]()
Line Chart
from matplotlib import pyplot as plt
x=[5,8,10]
y=[12,16,6]
[Link](x,y)
[Link]("info")
[Link]("Y AXIS")
[Link]("X AXIS")
[Link]()
Pie Chart
import [Link] as plt
●
import numpy as np
●
y = [Link]([35, 25, 25, 15])
●
mylabels = ["Apples", "Bananas", "Cherries", "Dates"]
●
[Link](y, labels = mylabels)
●
[Link]()
●
Bar graph:
from matplotlib import pyplot as plt
x1=[5,8,10]
y1=[12,16,6]
x2=[6,9,11]
y2=[6,15,7]
[Link](x1,y1,color='g')
[Link](x2,y2,color='r')
[Link]("info")
[Link]("Y AXIS")
[Link]("X AXIS")
HISTOGRAM:
from matplotlib import pyplot as plt
age=[5,8,22,21,20,22,43,67,89,45,25]
bin=[0,10,20,30,40,50,60,70,80,90,100]
[Link](age,bin,histtype='bar',rwidth=10)
[Link]("histogram")
[Link]("Y AXIS")
[Link]("X AXIS")
[Link]()
SCATTER PLOT
import [Link] as plt
import numpy as np
x = [Link]([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = [Link]([99,86,87,88,111,86,103,87,94,78,77,85,86])
[Link](x, y)
[Link]()
import [Link] as plt
●
import numpy as np
●
#day one, the age and speed of 13 cars:
●
x = [Link]([5,7,8,7,2,17,2,9,4,11,12,9,6])
●
y = [Link]([99,86,87,88,111,86,103,87,94,78,77,85,86])
●
[Link](x, y)
●
#day two, the age and speed of 15 cars:
●
x = [Link]([2,2,8,1,15,8,12,9,7,3,11,4,7,14,12])
●
y = [Link]([100,105,84,105,90,99,90,95,94,100,79,112,91,80,85])
●
[Link](x, y)
●