0% found this document useful (0 votes)
7 views11 pages

XII IP (065) Study Material

Uploaded by

limabeans
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views11 pages

XII IP (065) Study Material

Uploaded by

limabeans
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

INFORMATICS PRACTICES (065) - XII BY G SIVA PRASAD (PGT)

Plotting with pyplot


 Data visualization is the technique to present the data in a pictorial or graphical format.
 It enables stakeholders and decision makers to analyze data visually.
 The data in a graphical format allows them to identify new trends and patterns easily.
 The main benefits of data visualization are as follows:
 It simplifies the complex quantitative information
 It helps analyze and explore big data easily
 It identifies the areas that need attention or improvement
 It identifies the relationship between data points and variables
 It explores new patterns and reveals hidden patterns in the data
 The matplotlib is a python library that provides many interfaces functionally for 2D graphics similar
to MATLAB’s in various form.
 pyplot is a collection of methods within matplotlib which allows user to construct 2D plots easily
and interactively.
 The syntax to import pyplot is

import matplotlib.pyplot
(or)
import matplotlib.pyplot as plt

 As per our syllabus, we will discuss about the following charts in python.
(1) Line charts
(2) Scatter charts
(3) Bar charts
(1) Line charts
 Alinechartorlinegraphisatypeofchartwhichdisplaysinformationasaseriesof data
points called markers connected by straight line segments.
 plot() method is used to construct linecharts.
 Syntax:
matplotlib.pyplot.plot(data1,data2,color,marker,linestyle,type,markeredgecolor… )

Where,
 ‘color’ represents line color and values will be like black or k (black color), blue or b (blue color),
red or r (red color), etc.
 ‘linestyle’ represents type of line and values willbe like solid or dashed or dashdot or
dotted
 ‘markeredgecolor’ edgecolor of themarker. Thevalues of this parameters as like color
values.

35
INFORMATICS PRACTICES (065) - XII BY G SIVA PRASAD (PGT)

 ‘marker’ represents marker type as follows.

 Eg (1):

OUTPUT:

36
INFORMATICS PRACTICES (065) - XII BY G SIVA PRASAD (PGT)

(2) Scatter charts


 The scatter chart is a graph of plotted points on two axes that show the relationship between two
sets ofdata.
 The scatter charts can be created through two functions of pyplot library:
plot( ) function
scatter() function
 Syntax of plot() function is –
matplotlib.pyplot.plot(data1,data2,marker,color,markersize)

Where, markersize represents size of the marker.


Remaining all parameters are same as line chart syantax.
 Eg (1):

OUTPUT:

37
INFORMATICS PRACTICES (065) - XII BY G SIVA PRASAD (PGT)

(3) Bar charts


 A Bar Graph / Chart is a graphical display of data using vertical bars or horizontal of different
heights.
 The bar graph can created by using the following methods.
(a) bar()
(b) barh()
 bar() is used to create vertical bar graphs.
 barh() is used to create horizontal bar graphs.
 Syntax:

matplotlib.pyplot. bar(data1,data2)
(or)
matplotlib.pyplot. barh(data1,data2)

 Eg(1):

OUTPUT:

38
INFORMATICS PRACTICES (065) - XII BY G SIVA PRASAD (PGT)

 Eg (2): Above example1 using barh()

OUTPUT:

 Eg (3) : above example2 with different colors

OUTPUT:

39
INFORMATICS PRACTICES (065) - XII BY G SIVA PRASAD (PGT)

 Eg (4):

OUTPUT:

Note: for the differences in between bar graphs and histograms, please refer histogram topic.

4.Histogram
 A histogram is a plot that show the underlying frequency distribution of a set of
continuous data.
 In pandas, hist() function is used to create histogram.
 It is an accurate graphical representation of the distribution of numerical data.
 It is similar to bar graph, but a bar chart majorly represents categorical data (data
that has some labels associated with it), while histograms on the other hand, is

40
INFORMATICS PRACTICES (065) - XII BY G SIVA PRASAD (PGT)

used to describe distributions.

 To create histograms, we have to use matplotlib library as follows


import matplotlib.pyplot as plt

 Syntax:
plt.hist(data,bins,rwidth,label,bordercolor,,color)
Where,
data represents dataset(s).
bins represents bins intervals.
rwidth represents each bin width
label represents name(s) of dataset(s).
bordercolor represents border color of every bin.
color represents color(s) of dataset(s).

 The following methods can also be used in the creation of histograms:


 plt.title()
Used to set title to the histogram.
 plt.xlabel()
Used to set name x-axis to the histogram.

 plt.ylabel()
Used to set name y-axis to the histogram.

 plt.show()
Used to display the histogram.

41
INFORMATICS PRACTICES (065) - XII BY G SIVA PRASAD (PGT)

 Eg(1): Histogram creation with one datasets with default bins values.

OUTPUT:

42
INFORMATICS PRACTICES (065) - XII BY G SIVA PRASAD (PGT)

 Eg(2): Histogram creation with one datasets with default bins values.

OUTPUT:

43
INFORMATICS PRACTICES (065) - XII BY G SIVA PRASAD (PGT)

 Eg(3): Histogram creation with two datasets.

OUTPUT:

44
INFORMATICS PRACTICES (065) - XII BY G SIVA PRASAD (PGT)

 Eg(4): Histogram with grids.

OUTPUT:

45

You might also like