Docsity

Data Visualization in Python: A Beginner's Guide to Matplotlib - Prof. Gu, Lecture notes of Computer Science

Toggle sidebar
bg1
Data visualization
Meaning
โž”
It
is
the
representation
of
data
and
information
in
a
graphical
or
pictorial
form
such
as
charts
,graphs
,
maps and images
โž”
The
data
in
python
is
visualized
using
the
โ€˜
matplotlib
โ€˜
library
which
is
used
to
form
the
charts
like
line
,
bar , scatter etc
Advantages
1.
Improved understanding
2.
Better decision making
3.
Increased efficiency
4.
Improved communication
5.
Enhanced collaboration
Steps
1.
Generating the data
2.
Importing the used library
3.
Creating the visualization
4.
Customizing visualization
5.
Saving or displaying visualizations
Type of visualization in matplotlib
1.
Line chart
2.
Bar chart
3.
Histogram
4.
Scatter plots
5.
Pie charts
6.
Box plots
7.
3d plots
Steps to plot a simple line graph
1.
Import mathplotlib library called as as plt
2.
Prepare
the
data
to
be
plotted
,
it
is
done
by
creating
2
arrays , 1 as x axis and other as y axis
3.
Call
the
plot
function
from
the
matplotlib
library
and
pass it to x and y data
4.
Add the title to the plot using the title function
5.
Add
labels
to
the
x
and
y
axis
using
x
label
and
y
label
function
6.
Show the plot using the show function
7.
The
plot
will
be
displayed
in
a
new
window
we
can
save the plot using the save fig fun
Eg -
Import matplotlib.pyplot as plt
X = [ 1 , 2 ,3 , 4 , 5 ]
Y = [ 1,4,9,16,25 ]
Plt.plot ( x , y )
Plt.title ( โ€œ simple line graph โ€œ )
Plt . xlable ( โ€œ numbers โ€œ)
Plt.ylabel ( โ€œ square โ€œ )
plt.show()
Plt.savefig ( โ€œ graph. Png โ€œ )
Important methods of mathplotlib
Method
1.
Plot
2.
Scatter
3.
Hist
4.
Bar
5.
Pie
6.
Title
7.
Xlabel
Description
โž”
To
plot
data
on
the
graph
โž”
It
is
used
to
create
a scatter plot
โž”
To
create
a
histogram
โž”
To
create
a
bar
Example
Plt.plot ( x ,y )
Plt.scatter
(
x
, y )
Plt.hist
(
data
)
Plt.bar(
x
,height)
8.
Ylabel
9.
Xlim
10.
Ylim
11.
Xsticks
12.
Ystic
ks
graph
โž”
To
create
a
pie
chart
โž”
To
give
the
title
to
the graph
โž”
Used
to
label
the
x
axis
โž”
Used
to
label
the
y
axis
โž”
Used
to
set
limit
for
the x axis
โž”
Used
to
set
limit
for
the y axis
โž”
Used
to
et
tick
mark
on x axis
โž”
Used
to
set
tick
mark on y axis
Plt.pie
(
sizes
)
Plt.
title
(
โ€œ
ng
โ€œ )
Plt.xlabel
(โ€œabc โ€œ )
Plt.ylabel
(
โ€œ
qwr โ€œ )
Plt.xlim ( 0, 10)
Plt.ylim
(
0
,
100 )
Plt.xticks
(
range
,
0
,
11
,1
)
Playsticks
(
range
,
0
,
10
,
2
)
pf2

Partial preview of the text

Download Data Visualization in Python: A Beginner's Guide to Matplotlib - Prof. Gu and more Lecture notes Computer Science in PDF only on Docsity!

Meaning โž”It is the representationData visualization of data and information in a โž”^ graphical^ maps and imagesThe data inor python^ pictorial is visualized^ form^ such using^ as^ chartsthe โ€˜ matplotlib^ ,graphs^ ,โ€˜ Advantages^ library^ bar , scatter etc^ which^ is^ used^ to^ form^ the^ charts^ like^ line^ ,

      1. Improved understandingBetter decision makingIncreased efficiency Steps^ 4.^ 5.^ Improved communicationEnhanced collaboration
      1. Generating the dataImporting the used libraryCreating the visualization
    1. Customizing visualizationSaving or displaying visualizations

Type of visualization in matplotlib 1. 2. Line chartBar chart

      1. HistogramScatter plotsPie charts Steps to plot a simple line graph^ 6.^ 7.^ Box plots3d plots
    1. Import mathplotlib library called as as pltPrepare arrays , 1 as x axis and other as y axis the data to be plotted , it is done by creating 2
    1. Call pass it to x and y dataAdd the title to the plot using the title function the plot function from the matplotlib library and
    1. Add functionShow the plot using the show function labels to the x and y axis using x label and y label
  1. The save the plot using the save fig fun plot will be displayed in a new window we can Eg - Import matplotlib.pyplot as plt X = [ 1 , 2 ,3 , 4 , 5 ] Y = [ 1,4,9,16,25 ] Plt.plot ( x , y ) Plt.title ( โ€œ simple line graph โ€œ ) Plt. xlable ( โ€œ numbers โ€œ) Plt.ylabel ( โ€œ square โ€œ ) plt.show() Plt.savefig ( โ€œ graph. Png โ€œ ) Important methods of mathplotlib Method 1. 2. PlotScatter
      1. HistBarPie
    1. TitleXlabel

Description โž”To graph plot data on the โž” โž”It a scatter plotTo is usedcreate to create a โž”^ histogramTo create a bar

Example Plt.plot ( x ,y ) Plt.scatter ( x , y ) Plt.hist ) ( data Plt.bar( ,height) x

      1. YlabelXlim Ylim
  1. 12.Xsticks ks Ystic โž”^ graphTo chart create a pie โž” โž”To the graphUsed give to labelthe title the tox โž”^ axisUsed axis to label the y โž” โž”Used the x axisUsed toto setset limitlimit forfor โž”^ the y axisUsed on x axis to et tick mark โž”Used mark on y axis to set tick

Plt.pie ) Plt. title ( (sizes โ€œ ng โ€œ ) Plt.xlabel (โ€œabc โ€œ ) Plt.ylabel qwr โ€œ ) Plt.xlim ( 0, 10) ( โ€œ Plt.ylim 100 ) Plt.xticks ( (^0) (, range ) Playsticks , 0 , 11 ,1( range ) , 0 , 10 , 2

Plot method parameters for customizing a line graph 1. 2. X - the x coordinate of the plotY - the y coordinate of the plot

  1. Line style a.it plotted points is used to control the style of line connecting the
  2. linewidth^ b.^ It^ ,dashost ,none etc^ accepts^ the^ value^ solid^ ,^ dotted^ ,^ dashed
  3. Line Colour^ a.^ b.^ It is used to control the width of the lineThe default value is 0 a. b. It the plotted pointEg - color = โ€œ red โ€œ is used to control the color of the line connecting
  4. Marker 7. Markersize a.It is used to control the shape of the marker a.It is used to control the size of the marker
  5. Markeredgecolorb. a.^ Eg - markersize = 10It is used to control the edge of a marker
  6. Markeredgewidth^ b. a.^ Eg - markeredgecolor = โ€œ red โ€œUsed to control the width of the edge of the marker
  7. Markerfacecolor^ b. a.^ Eg - markeredgewidth = 2It is used to control the color of the face of the
  8. Label a.^ markerIt is used to specify a label for the plotted data Random walk โž”It sequence is a ofmathematical steps or movements concept thatthat aredescribes randomly a โž”^ determinedIt that can not be predicted with certainty can be thought as a series of events or decisions โž”Types are 1. Discrete
      1. Continuous - eg : traffic flow in a cityAnimal migrationRandom surfing on the internet Plotly โž”It^ 5. Spread of diseasesis a data visualization library for creating โž”^ interactive and visually appealing data visualizationIt that can be easily understood by people is usually used to turn data into charts and graph โž”In browser formats such as html or pdf plotly saved visualizations as a image can file be ordisplayed exported in to a otherweb Api [ application programming interface ] โž”Set software and applications of protocols , routines and tools for building โž”It systems access the data of another system allows or (^) platformsfor communications where it allowsbetween 1 systemdifferent to