XII IP (065) Study Material
XII IP (065) Study Material
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)
Eg (1):
OUTPUT:
36
INFORMATICS PRACTICES (065) - XII BY G SIVA PRASAD (PGT)
OUTPUT:
37
INFORMATICS PRACTICES (065) - XII BY G SIVA PRASAD (PGT)
matplotlib.pyplot. bar(data1,data2)
(or)
matplotlib.pyplot. barh(data1,data2)
Eg(1):
OUTPUT:
38
INFORMATICS PRACTICES (065) - XII BY G SIVA PRASAD (PGT)
OUTPUT:
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)
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).
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)
OUTPUT:
44
INFORMATICS PRACTICES (065) - XII BY G SIVA PRASAD (PGT)
OUTPUT:
45