Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

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

A comprehensive introduction to data visualization in python using the matplotlib library. It covers the fundamental concepts of data visualization, including its meaning, advantages, and steps involved. The document also explores various types of visualizations available in matplotlib, such as line charts, bar charts, histograms, scatter plots, pie charts, box plots, and 3d plots. It further delves into the steps involved in plotting a simple line graph and provides a detailed explanation of important matplotlib methods and their parameters for customizing visualizations. Additionally, the document touches upon the concept of random walks and introduces the plotly library for creating interactive visualizations.

Typology: Lecture notes

2023/2024

Available from 12/11/2024

neha-gupta-28
neha-gupta-28 🇮🇳

3 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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