Q. What do you mean by Data Visualization?
Ans. Data Visualization basically refers to the graphical or
pictorial representation of information and data using
visual components like charts, graphs and maps etc. It is
immensely useful in decision making and very easy to
understand ana d analyse the entire scenario.
Q. What do you mean by Matplotlib?
Ans. The matplotlib is a Python Library that provides many
interfaces and functionality for 2-D graphics. It is a high quality
plotting library of Python.
Matplotlib library is used for creating static, animated,
and interactive 2D- plots or figures in Python. It can
be installed using the following pip command from the
command prompt:
pip install matplotlib
[Link] is PyPlot?
Ans. PyPlot is a section/interface of matplotlib. It is a
collection of methods within matplotlib library which allows
users to construct 2-D plots/charts easily and interactively.
For plotting using Matplotlib, we need to import its Pyplot
module using the following command:
import [Link] as plt
Q. Write the import statement to import matplotlib
library to plot any chart.
Ans. import [Link] as plt
import [Link]
Q. What are the various types of charts?
Ans: Prepare from Sumita Arora’s Book.
Practical Q. No. – 01
Write a program to accept a list that stores marks of a student
in four Unit test. Draw/Plot the students performance in these
4 Unit Tests (Unit test wise). Use suitable titles, x-axis title, y-
axis title, grid lines, line colour, line style, marker, marker size
etc.
Practical Q. No. – 02
Write a program to accept onion prices of last 6 months. Plot
the line chart to show the prices of onion in last six months.
Use suitable titles, grid, line colour etc.
Line Chart :
File name : plot__line - demo 1 NCERT
Data Source : List
import [Link] as plt
#list storing date in string format
date=["25/12","26/12","27/12","28/12"]
#list storing temperature values
temp=[8.5,10.5,6.8,12.6]
#create a figure plotting temp versus date
[Link](date, temp, marker="d")
[Link]("Temperature of Days")
[Link]("Days")
[Link]("Temperature")
[Link](True)
#save the figure
[Link]('e:/[Link]')
#show the figure
[Link]()
File name : plot_line_1C_School_Average_Demo
Data Source : List
import [Link] as plt
year = [2015,2016,2017,2018,2019,2020]
schavg = [85.0,88.0,90.0,86.0,89.0,91.0]
[Link](figsize=(10,5))
[Link](year, schavg, 'b*', linestyle='solid', linewidth=2, markersize=25,
markeredgecolor='r')
[Link]("Year")
[Link]("School Average")
[Link]("Performance Chart")
[Link](True)
File name : plot_line_1B_School_Average
Data Source : List
import [Link] as plt
#import numpy as np
year=[2015,2016,2017,2018,2019,2020]
schavg=[83,86,85,83,86,92]
[Link](figsize=(10,7))
[Link](year, schavg, 'ro' , linestyle='solid', linewidth=6, markersize=25,
markeredgecolor='b')
[Link]("Year")
[Link]("School Average")
import numpy as np
import [Link] as pl
a= [Link](['Arush', 'Anaya', 'Om','Raj', 'Tim'])
b=[Link]([50,60,40,80,70])
#c=[Link]([1,4,9,16])
[Link]("Performance Chart")
[Link]("Name")
[Link]("Marks Obtained")
[Link](a,b)
[Link](True)
File name : Plot_Line_1D_KV_JNV_Legends
Data Source : List
import numpy as np
import [Link] as plt
#year = [2014,2015,2016,2017,2018]
year=[Link]([2014,2015,2016,2017,2018])
jnvpasspercentage = [90,92,94,95,97]
kvpasspercentage = [89,91,93,95,98]
[Link](figsize=(12,7))
[Link](year, jnvpasspercentage, color='g')
[Link](year, kvpasspercentage, color='orange')
[Link]('Year', fontsize=15)
[Link]('Pass percentage', fontsize=15)
[Link]('JNV KV PASS % till 2018')
[Link](('jnv','kv'), loc='upper right', frameon=False)
[Link](True)
[Link]()
File name : plot_line_1A_schaverage.py
Data Source : List
import [Link] as plt
year=['2015','2016','2018','2019','2020']
schavg= [89.0,86.0,79.0,90.0,81.0]
high_perc =[89,94,96,83,90]
[Link](figsize=(12,7))
[Link](year, schavg ,'g', linewidth=5, linestyle='dashed')
[Link](year, high_perc, 'r', linewidth=5, marker='*', markersize=40,
markeredgecolor='blue')
[Link]("YEAR")
[Link]("SCHOOL AVERAGE")
[Link]("Performace Chart using Line Graph")
[Link](True)
[Link]()
Data Source : Dataframe
import pandas as pd weight height
import [Link] as plt 0 50 121.5
weight=[50,51,52,57,59] 1 51 122.5
height=[121.5, 122.5, 120.2, 119.0, 124] 2 52 120.2
dict1= {"weight": weight, "height": height} 3 57 119.0
df1=[Link](dict1) 4 59 124.0
print(df1)
[Link]( [Link], [Link], color='b', marker='*', markersize=20,
linewidth= 5, linestyle="dashdot")
[Link]("Weight in Kgs.")
[Link]('Height in cm')
#Set chart title:
[Link]('Average weight with respect to average height')
[Link](True)
[Link]([Link])
[Link]()
File name : plot__line - demo 3 NCERT
Data Source : DataFrame
import [Link] as plt
import pandas as pd
height=[80,90,100,90,110,100]
weight=[20,22,24,26,28,30]
length=[115,120,125,115,130,125]
df=[Link]({"height":height,"weight":weight, "length":length})
print(df)
[Link](figsize=(12,8))
[Link]([Link],[Link], label= 'KVS', color='b', marker='*',markersize=20,
linewidth=2, linestyle='dashdot')
[Link]([Link],[Link], label = 'DAV', color='r', marker='D',markersize=10,
linewidth=2, linestyle='dashdot')
[Link](loc="upper right", fontsize=25)
[Link]('Weight in kg')
[Link]('Height in cm')
[Link]('Average weight with respect to average height')
[Link]()
Data Source : Dataframe & CSV file
import pandas as pd
import [Link] as plt
df1= pd.read_csv("C:/Users/hp/Desktop/1- BRDAV/CLASS XII PPT &
VIDEOS/Demo & CSV File Operations/[Link]")
print(df1)
[Link](figsize=(10,7))
[Link]([Link], df1.Week1, 'b', label='week1')
[Link]([Link], df1.Week2, 'g', label='week2')
[Link]([Link], df1.Week3, 'r', label='week3')
[Link](loc="upper right")
[Link]("e:[Link]")
[Link]()
Dayname Week1 Week2 Week3
0 Monday 10000 34000 56000
1 Tuesday 12000 20000 45000
2 Wednesday 15000 25000 35000
Data Source : Dataframe & CSV file
import pandas as pd
import [Link] as plt
df1= pd.read_csv("C:/Users/hp/Desktop/1- BRDAV/CLASS XII PPT &
VIDEOS/Demo & CSV File Operations/[Link]")
print(df1)
[Link](figsize=(10,7))
[Link](kind="line", x= 'Dayname', color=['blue','green','red'])
#[Link](ticks, [Link])
[Link]()
Dayname Week1 Week2 Week3
0 Monday 10000 34000 56000
1 Tuesday 12000 20000 45000
2 Wednesday 15000 25000 35000
Bar Chart
File name : plot_bar_1A_schoolAvrage for [Link]
Data Source : DataFrame
import [Link] as plt
import pandas as pd
year=[2015,2016,2017,2018,2019]
schavg= [89.0,86.0,79.0,90.0,81.0]
df1=[Link]({"year":year, "schavg": schavg})
print(df1)
[Link](figsize=(10,7))
[Link]([Link],[Link])
[Link]("YEAR")
[Link]("SCHOOL AVERAGE")
[Link]("Performace Chart using Bar Graph")
[Link]()
File name : plot_Bar_1B_yearwise_subjectAverage _twoInOne
Data Source : List
import [Link] as plt
import numpy as np
years=['2015', '2016', '2017', '2018']
percentage=[82,83,85,90]
[Link](figsize=(10,5))
[Link](years, percentage, align='center', color=['r','b','g','y'])
[Link]("Pass Percentage")
[Link]('Years')
[Link]()
File name : plot_Bar_1B_yearwise_subjectAverage _twoInOne
Data Source : List
year=['2015', '2016', '2017', '2018']
percentage=[95,83,85,90]
[Link](figsize=(10,5))
[Link](year, percentage, color='Blue', width=0.5)
[Link](year, fontsize=25, color ='r', rotation=30)
[Link](percentage, fontsize=25, rotation=0)
[Link]("Pass Percentage", fontsize=25, color= 'g')
[Link]('Years', fontsize=25, color= 'b')
[Link]()
Summary :
• A plot is a graphical representation of a data set which is also
interchangeably known as a graph or chart. It is used to show the
relationship between two or more variables.
• In order to be able to use Python’s Data Visualisation library, we need to
import the pyplot module from Matplotlib library using the following
statement: import [Link] as plt, where plt is an alias or an
alternative name for [Link]. You can keep any alias of your
choice.
• The pyplot module houses functions to create a figure(plot), create a
plotting area in a figure, plot lines, bars, hist. etc., in a plotting area,
decorate the plot with labels, etc.
• The various components of a plot are: Title, Legend, Ticks, x label, ylabel
• [Link]() is used to build a plot, where plt is an alias.
• [Link]() is used to display the figure, where plt is an alias.
• [Link]() and [Link]() are used to set the x and y label of the plot.
• [Link]() can be used to display the title of a plot.
• It is possible to plot data directly from the DataFrame.
• Pandas has a built-in .plot() function as part of the DataFrame class.
• The general format of plotting a DataFrame is [Link](kind = ' ')
where df is the name of the DataFrame and kind can be line, bar, hist,
scatter, box depending upon the type of plot to be displayed.