STUDY MATERIAL
OPEN IN APP
Home / Class 12 - Informatics Practices Preeti Arora / Data Visualization using Matplotlib
Chapter 2
Data Visualization using
Matplotlib
Class 12 - Informatics Practices Preeti Arora
Fill in the Blanks
Question 1
Data Visualization refers to the graphical or
visual representation of information and data
using visual elements like charts, graphs and
maps, etc.
Question 2
Pyplot is a collection of methods with Matplotlib
library which allows the user to construct 2D plots
easily and interactively.
Question 3
The line chart is a graph of plotted points on two
axes connected by a straight line.
Question 4
Title is the text that appears on the top of the plot
and defines what the chart is about.
Question 5
The axes of a plot can be labelled using xlabel()
and ylabel() functions.
Question 6
A histogram is a summarization tool for discrete
or continuous data.
Question 7
Pyplot module's hist() let us create histograms.
Question 8
In a bar chart, each column represents a group
defined by a categorical variable.
Question 9
barh() function is used to create horizontal bar
chart.
Question 10
The area on which actual plot will appear is
defined by axes.
Question 11
Bins describe the number of data points that fall
within a specified range of values.
Question 12
To change the orientation of the histogram, we
can use orientation argument with hist().
Question 13
Legends are used to explain different sets of
data plotted in different colors or marks in the
chart.
State True or False
Question 1
The Matplotlib is a Python interface.
Answer
False
Reason — Matplotlib is an open-source 2D
plotting library for the Python programming
language that helps in visualizing figures.
Question 2
To save the plot, we have to use save graph()
function.
Answer
False
Reason — To save the plot, we have to use
savefig() function.
Question 3
Plot can be saved in a pdf format.
Answer
True
Reason — Matplotlib supports saving plots in
various formats, including PDF. We can use the
savefig() function and specify the file extension
as .pdf to save the plot in PDF format. For
example, to save the bar_plot as a PDF file, we
use the following statement :
[Link]("bar_plot.pdf") .
Question 4
We can specify different colors for different bars
of a bar chart.
Answer
True
Reason — In Matplotlib, we can specify different
colors for different bars of a bar chart by passing
a list of colors to the bar() function. The syntax
is [Link](x, y, color=[color1,
color2,.....]) .
Question 5
To use pyplot for data visualization, we have to
import it by giving import command: import
[Link]
Answer
True
Reason — To use pyplot for data visualization,
we need to import it from the matplotlib library
using the command import [Link] .
Question 6
Pyplot is a Python library.
Answer
False
Reason — Pyplot is a module of matplotlib
library of Python containing collection of methods
which allows a user to create 2D plots and
graphs easily and interactively.
Question 7
To specify a common width for all bars in a bar
graph, we have to use thick argument.
Answer
False
Reason — To specify a common width for all
bars in a bar graph, we have to use the width
argument.
Question 8
To add a title to the plot, we have to call function
header().
Answer
False
Reason — The title() function is used to set a
title for the plot.
Question 9
Markers are data points in the graphs.
Answer
True
Reason — The data points being plotted on a
graph/chart are called markers.
Question 10
Line style argument of plot() function is not
required in scatter chart.
Answer
True
Reason — When creating scatter charts using
Matplotlib's plot() function, the linestyle
argument is skipped because scatter plots do not
use line styles.
Question 11
When we don't specify X or Y limits for a plot,
then pyplot does not automatically decide limits
as per values being plotted.
Answer
False
Reason — When we don't specify X or Y limits
for a plot, pyplot automatically decides the limits
based on the values being plotted. It sets the
limits to the minimum and maximum values of the
data, so that all the data points are visible in the
plot.
Multiple Choice Questions
Question 1
Which Python package is used for 2D graphics?
1. [Link]
2. [Link]
3. [Link]
4. [Link]
Answer
[Link]
Reason — A Python package
[Link] is used for creating 2D
graphics, including plots, charts, and graphs.
Question 2
The most popular data visualization library in
Python is:
1. pip
2. matinfolib
3. matplotlib
4. matpiplib
Answer
matplotlib
Reason — Matplotlib is the most popular data
visualization library in Python.
Question 3
Matplotlib allows you to create:
1. table
2. charts
3. maps
4. infographics
Answer
charts
Reason — Matplotlib is used for creating static,
animated and interactive 2D-plots or figures in
Python. It is a plotting library that provides a wide
range of chart types, including line plots, scatter
plots, bar charts, histograms etc.
Question 4
Which of the following is not a visualization under
Matplotlib?
1. Line plot
2. Histogram
3. Bar plot
4. Table plot
Answer
Table plot
Reason — Matplotlib is a plotting library that
provides various visualization tools, including line
plots, scatter plots, histograms, and bar plots.
Question 5
Which of the following commands is used to
install Matplotlib for coding?
1. import [Link] as plot
2. import [Link] as pt
3. import [Link] as plot
4. import [Link] as plt
Answer
import [Link] as plt
Reason — The correct command to import
Matplotlib for coding is import [Link]
as plt . This is the standard way to import
Matplotlib, where [Link] is the
module that provides the plotting functions, and
as plt assigns the alias plt to the pyplot
module.
Question 6
Which of the following methods should be
employed in the code to display a plot()?
1. show()
2. display()
3. execute()
4. plot()
Answer
show()
Reason — In Matplotlib, the show() method is
used to display a plot.
Question 7
Which of the following statements is used to
create a histogram of 'step' type with 20 bins?
1. [Link](x, bins = 20, histtype = "barstacked")
2. [Link](x, bins=20)
3. [Link](x, bins=20, histtype="step")
4. [Link](x, bins=20, histtype=hist())
Answer
[Link](x, bins=20, histtype="step")
Reason — The histtype parameter in the
hist() function is used to specify the type of
histogram to be created. In this case,
histtype="step" is used to create a step
histogram. The bins=20 parameter specifies that
the histogram should be divided into 20 bins.
Hence, the correct statement is [Link](x,
bins=20, histtype="step") .
Question 8
The part of chart which identifies different sets of
data plotted on plot by using different colors is
called:
1. legends
2. title
3. axes
4. figure
Answer
legends
Reason — A legend is a part of a chart that
identifies different sets of data plotted on the plot
by using different colors, symbols.
Question 9
Which of the following is an incorrect example of
savefig() function?
1. [Link]("[Link]" )
2. [Link]("[Link]")
3. [Link]("[Link]")
4. [Link]("[Link]")
Answer
[Link]("[Link]")
Reason — The savefig() function in matplotlib
is used to save a figure to a file. It supports
various file formats such as PDF, PNG, EPS,
SVG, etc. However, PPT (PowerPoint) is not a
supported file format for saving figures in
matplotlib.
Question 10
Which of the following plots makes it easy to
visualize a trend in data over intervals of time.
1. Box plot
2. Histogram
3. Line Chart
4. Bar chart
Answer
Line Chart
Reason — A line chart is a type of plot that
displays data as a series of points connected by
lines, making it easy to visualize trends in data
over intervals of time.
Question 11
COVID-19 patient analysis in the Mumbai region
is to be plotted. The command used to give title
to X-axis as "No. of Patients" in the graph is:
1. [Link]()
2. [Link]("No. of Patients")
3. [Link]("No. of Patients")
4. [Link]("No. of Patients")
Answer
[Link]("No. of Patients")
Reason — The [Link]() function is used to
set the label for the x-axis of a plot. In this case,
the command [Link]("No. of Patients")
sets the x-axis label to "No. of Patients", which is
suitable for a COVID-19 patient analysis in the
Mumbai region.
Question 12
Python Matplotlib ............... is used to compare
different categorical or discrete variables.
1. line plot
2. bar graph
3. histogram
4. boxplot
Answer
bar graph
Reason — A bar graph is a type of plot that uses
rectangular bars with heights or lengths
proportional to the values they represent to
compare different categorical or discrete
variables.
Assertions and Reasons
Question 1
Assertion (A): Data Visualization helps users in
analyzing a large amount of data in a simple way.
Reasoning (R): Data Visualization makes
complex data more accessible, understandable
and usable.
1. Both A and R are true and R is the correct
explanation of A.
2. Both A and R are true but R is not the correct
explanation of A.
3. A is true but R is false.
4. A is false but R is true.
Answer
Both A and R are true and R is the correct
explanation of A.
Explanation
Data visualization refers to the graphical or visual
representation of information and data using
visual elements like charts, graphs, and maps.
These visual tools help in analyzing a large
amount of data in a simple way. Because of this,
data visualization makes complex data more
accessible, understandable, and usable.
Question 2
Assertion (A): import [Link] as plt is
used to import pyplot module.
Reasoning (R): Matplotlib is a Python library and
pyplot is a module that contains functions to
create various plots.
1. Both A and R are true and R is the correct
explanation of A.
2. Both A and R are true but R is not the correct
explanation of A.
3. A is true but R is false.
4. A is false but R is true.
Answer
Both A and R are true and R is the correct
explanation of A.
Explanation
The command to import pyplot is import
[Link] as plt. Matplotlib is a Python 2D
plotting library for creating publication-quality
figures. Pyplot is a module within the Matplotlib
library that contains a collection of methods
which allow users to create 2D plots and graphs
easily and interactively.
Question 3
Assertion (A): Data Visualization refers to the
graphical representation of information and data
using visual elements like charts, graphs and
maps, etc.
Reasoning (R): To install matplotlib library, we
can use the command - pip install matplotlib.
1. Both A and R are true and R is the correct
explanation of A.
2. Both A and R are true but R is not the correct
explanation of A.
3. A is true but R is false.
4. A is false but R is true.
Answer
Both A and R are true but R is not the correct
explanation of A.
Explanation
Data visualization refers to the graphical or visual
representation of information and data using
visual elements like charts, graphs, and maps. To
install the Matplotlib library, we use the command
pip install matplotlib .
Question 4
Assertion (A): A histogram is basically used to
represent data provided in the form of groups
spread in non-continuous ranges.
Reasoning (R): [Link]() function is
used to compute and create histogram of a
variable.
1. Both A and R are true and R is the correct
explanation of A.
2. Both A and R are true but R is not the correct
explanation of A.
3. A is true but R is false.
4. A is false but R is true.
Answer
A is false but R is true.
Explanation
A histogram is used to represent data provided in
the form of discrete or continuous ranges. The
[Link]() function is used to
compute and create a histogram of a variable.
Question 5
Assertion (A): legend (labels = ['Text']) is used to
give title to the graph.
Reasoning (R): [Link]("path") will save the
current graph in png or jpeg format.
1. Both A and R are true and R is the correct
explanation of A.
2. Both A and R are true but R is not the correct
explanation of A.
3. A is true but R is false.
4. A is false but R is true.
Answer
A is false but R is true.
Explanation
The statement legend(labels=['Text']) is used
to add a legend to the graph, not a title. The title
of the graph is set using [Link]('Title
Text') . The statement [Link]("path")
saves the current graph to the specified path in
PNG or JPEG format.
Question 6
Assertion (A): In histogram, X-axis is about bin
ranges whereas Y-axis talks about frequency.
Reasoning (R): The bins (intervals) must be
adjacent and are often (but are not required to
be) of equal size.
1. Both A and R are true and R is the correct
explanation of A.
2. Both A and R are true but R is not the correct
explanation of A.
3. A is true but R is false.
4. A is false but R is true.
Answer
Both A and R are true and R is the correct
explanation of A.
Explanation
A histogram's X-axis shows the bin ranges, which
are intervals for the data, and the Y-axis shows
the frequency of data points within each bin.
These bins must be adjacent to each other and
are often of equal size, although they don't have
to be.
Question 7
Assertion (A): Bar graph and histogram are
same.
Reasoning (R): A bar graph represents
categorical data using rectangular bars. A
histogram represents data which is grouped into
continuous number ranges and each range
corresponds to a vertical bar.
1. Both A and R are true and R is the correct
explanation of A.
2. Both A and R are true but R is not the correct
explanation of A.
3. A is true but R is false.
4. A is false but R is true.
Answer
A is false but R is true.
Explanation
Bar charts and histograms are not the same. A
bar chart or bar graph is a chart that presents
categorical data with rectangular bars, where the
heights or lengths of the bars are proportional to
the values they represent. On the other hand, a
histogram is a type of graph that provides a
visual interpretation of numerical data by
indicating the number of data points that lie within
a range of values, and this corresponds to a
vertical bar.
Question 8
Assertion (A): Marker has different elements
i.e., style, color, size, etc.
Reasoning (R): We can customize line of a line
chart by using marker property of plot() function.
1. Both A and R are true and R is the correct
explanation of A.
2. Both A and R are true but R is not the correct
explanation of A.
3. A is true but R is false.
4. A is false but R is true.
Answer
A is true but R is false.
Explanation
A marker in a chart or graph can have various
elements such as style (e.g., circle, square,
triangle), color, size, and others. The marker
property is used to customize the markers
(points) in a chart, not the line itself. The line in a
line chart can be customized using other
properties such as linestyle, linewidth, color, etc.
Case/Source Based Questions
Question 1
Hindustan Departmental Stores sell items of daily
use such as shampoo, soap and much more.
They record the entire sale and purchase of
goods month-wise so as to get a proper analysis
of profit or loss in their business transactions.
Following is the csv file containing the "Company
Sales Data".
Read the total profit of all months and show it
using a line plot. Total profit data has been
provided for each month. Generated line plot
must include the following properties:
X label name = Month Number
Y label name = Total profit
Answer
import pandas as pd
import [Link] as plt
df = pd.read_csv("C:\\company_sales_data.csv")
profitList = df['total_profit'].tolist()
monthList = df['month_number'].tolist()
[Link](monthList, profitList, label = 'Month
[Link]('Month number')
[Link]("Profit in dollars")
[Link](monthList)
[Link]('Company profit per month')
[Link]([100000, 200000, 300000, 400000, 50
[Link]()
Output
Question 2
Anirudh is trying to write a code to plot line graph
shown in the figure below. Help him fill in the
blanks in the code and get the desired output.
import [Link] as plt #
x = [1, 2, 3] #
y = [2, 4, 1] #
[Link](x, y, color = 'g') #
............... #
............... #
# giving a title to graph
plt. ............... ('My first graph!') #
# Function to show the plot
............... #
(i) Which of the above statements is responsible
for plotting the values on canvas?
1. Statement 8
2. Statement 4
3. Statement 1
4. None of these
(ii) Statements 5 & 6 are used to give names to
X-axis and Y-axis as shown in Fig.1. Which of the
following can fill those two gaps?
1.
[Link]('X - axis')
[Link]('Y - axis')
2.
[Link]('x - axis')
[Link]('y - axis')
3.
[Link]('x - axis')
[Link]('x - axis')
4.
[Link]('x axis')
[Link]('y axis')
(iii) Raman has executed code with first 7
statements but no output is displayed. Which of
the following statements will display the graph?
1. [Link]()
2. [Link]()
3. [Link]()
4. Both (b) & (c)
(iv) The number of markers in the above line
chart are:
1. Zero
2. Three
3. Infinite
4. Not defined
(v) Which of the following methods will result in
displaying 'My first graph!' in the above graph?
1. legend()
2. label()
3. title()
4. Both (a) & (c)
Answer
(i) Statement 4
Reason — The [Link]() statement is used to
plot y versus x data on the canvas in
Matplotlib.
(ii)
[Link]('X - axis')
[Link]('Y - axis')
Reason — The xlabel() and ylabel()
functions are used to give labels to x-axis and y-
axis respectively.
(iii) [Link]()
Reason — The [Link]() statement is used to
display the graph.
(iv) Three
Reason — There are three markers in the line
chart, corresponding to the three data points (1,
2), (2, 4), and (3, 1).
(v) title()
Reason — The [Link]() method is used to
set the title of the graph, which in this case is "My
first graph!".
Solutions to Unsolved Questions
Question 1
Plot a line chart for depicting the population for
the last 5 years as per the specifications given
below:
[Link]("My Title") will add a title "My Title" to
your plot.
[Link]("Year") will add a label "Year" to
your X-axis.
[Link]("Population") will add a label
"Population" to your Y-axis.
[Link]([1, 2, 3, 4, 5]) set the numbers on
the Y-axis to be 1, 2, 3, 4, 5. Pass it and
label as a second argument. For example, if
we use this code [Link]([1, 2, 3, 4, 5],
["1M", "2M", "3M", "4M", "5M"]), it will set the
labels 1M, 2M, 3M, 4M, 5M on the Y-axis.
[Link]() — works the same as [Link](),
but for the X-axis.
Answer
import [Link] as plt
[Link]([1, 2, 3, 4, 5], ['1M', '2M', '3M',
[Link]("My Title")
[Link]("Year")
[Link]("Population")
[Link]([1, 2, 3, 4, 5], ["2019", "2020", "
[Link]([1, 2, 3, 4, 5], ['1M', '2M', '3M',
[Link]()
Output
Question 2
What is Matplotlib?
Answer
Matplotlib is an open source 2D plotting Python
library for creating static, animated and
interactive figures.
Question 3
What do you mean by pyplot?
Answer
Pyplot is a module of matplotlib library of Python
containing collection of methods which allows a
user to create 2D plots and graphs easily and
interactively.
Question 4
How many types of graphs are plotted using
pyplot?
Answer
The types of graphs that can be plotted using the
pyplot module are as follows:
1. Line plots
2. Scatter plots
3. Bar charts
4. Histograms
5. Pie charts
6. Box plots
Question 5
Which function is used to show the graph?
Answer
The show() function is used to show the graph.
Question 6
Differentiate between figure and axes.
Answer
Figure Axes
Figure is the Axes is the
outermost area of individual plot within
Matplotlib graph. the figure.
It contains one or It contains two or
more than one axes. three axis objects.
Figure Axes
It contains plots, It contains title, an
legend, axis label, x-label and a y-
ticks, title etc. label.
It provides a canvas It displays the data
for the plot. in a specific format.
Question 7
What is the use of subplot() function? Write its
parameters.
Answer
The subplot() function is used to display
multiple charts in the same window.
The syntax of the subplot() function is:
subplot(nrows, ncols, index) .
The parameters are:
1. nrows: The number of rows in the grid of
subplots.
2. ncols: The number of columns in the grid of
subplots.
3. index: The index of the subplot to create,
starting from 1 and increasing from left to
right, top to bottom.
Question 8
Write a Python program to draw a line with a
suitable label in the X-axis and Y-axis, and a title.
Answer
import [Link] as plt
[Link]([1, 2, 3, 4, 5], [2, 4, 6, 8, 10])
[Link]("Line Graph")
[Link]("X-axis")
[Link]("Y-axis")
[Link]()
Output
Question 9
Write a Python program to plot two or more lines
with legends, different widths and colors.
Answer
import [Link] as plt
x1 = [10,20,30]
y1 = [20,40,10]
[Link](x1, y1, color='blue', linewidth=3, la
x2 = [10,20,30]
y2 = [40,10,30]
[Link](x2, y2, color='red', linewidth=4, lab
[Link]()
[Link]()
Output
Question 10
Write a Python program to plot two or more lines
and set the line markers.
Answer
import [Link] as plt
x1 = [10,20,30]
y1 = [20,40,10]
[Link](x1, y1, marker='o', label='line1-circ
x2 = [10,20,30]
y2 = [40,10,30]
[Link](x2, y2, marker='s', label='line2-squa
[Link]()
Output
Question 11
Write a Python program to display a bar chart of
the number of students in a class. Use different
colors for each bar.
Sample data:
Class: I, II, III, IV, V, VI, VII, VIII, IX, X
Strengths: 40, 43, 45, 47, 49, 38, 50, 37, 43, 39
Answer
import [Link] as plt
classes = ['I', 'II', 'III', 'IV', 'V', 'VI',
strengths = [40, 43, 45, 47, 49, 38, 50, 37, 4
[Link](classes, strengths, color=['red', 'gre
[Link]('Number of Students in Each Class')
[Link]('Class')
[Link]('Number of Students')
[Link]()
Output
Question 12
Write a Python program to display a horizontal
bar chart of the number of students in a class.
Sample data:
Class: I, II, III, IV, V, VI, VII, VIII, IX, X
Strengths: 40, 43, 45, 47, 49, 38, 50, 37, 43, 39
Answer
import [Link] as plt
classes = ['I', 'II', 'III', 'IV', 'V', 'VI',
strengths = [40, 43, 45, 47, 49, 38, 50, 37, 4
[Link](classes, strengths)
[Link]('Number of Students in Each Class')
[Link]('Number of Students')
[Link]('Class')
[Link]()
Output
Question 13
Plot a line graph for: y2 = 4*x
Answer
import [Link] as plt
import numpy as np
x = [Link](1, 5)
y = [Link](4 * x)
[Link](x, y)
[Link]('Line Graph of y² = 4x')
[Link]('x')
[Link]('y')
[Link]()
Output
Question 14
Write a Python program to plot the function y = x2
using the Matplotlib library.
Answer
import [Link] as plt
import numpy as np
x = [Link](1, 5)
y = x ** 2
[Link](x, y)
[Link]('Line Graph of y = x²')
[Link]('x')
[Link]('y')
[Link]()
Output
Question 15
Name the various methods used with pyplot
object.
Answer
The various methods used with 'pyplot' object are
as follows:
1. Plotting methods — plot(), scatter(), bar(),
hist() and pie().
2. Labeling and titling methods — xlabel(),
ylabel() and title().
3. Legend methods — legend().
4. axis methods — axis(), xlim(), ylim(), xticks()
and yticks().
5. grid methods — grid().
6. figure and axes methods — figure(),
subplots().
7. display and save methods — show(),
savefig() and close().
Question 16
Write the specific purpose of the following
functions used in plotting:
(a) show()
(b) legend()
Answer
(a) show() — The purpose of the show()
function is to display the plot.
(b) legend() — The purpose of the legend()
function is to add a legend to the plot. In a
chart/graph, there may be multiple datasets
plotted. To distinguish among various datasets
plotted in the same chart, legends are used.
Legends can be different colors/patterns
assigned to different specific datasets. The
legends are shown in a corner of a chart/graph.
Question 17
Plot a histogram of a class test of 40 students
based on random sets of marks obtained by the
students (MM=100).
Answer
import [Link] as plt
import numpy as np
marks = [Link](0, 101, 40)
[Link](marks)
[Link]('Class Test Marks')
[Link]('Marks')
[Link]('Frequency')
[Link]()
Output
Question 18
A list, namely temp contains average temperature
for seven days of last week. You want to see how
the temperature changes in the last seven days.
Which chart type will you plot for the same and
why?
Answer
A line chart is the suitable choice for visualizing
how the temperature changed over the last seven
days. The line chart shows trends over time and
displays continuous data, making it ideal for
representing temperature values. The chart's
ability to connect data points allows viewers to
easily observe temperature trends and
understand variations across the seven-day
period.
Question 19
Collect data about colleges in Delhi University or
any other university of your choice and number of
courses they run for Science, Commerce and
Humanities, store it in a CSV file and present it
using a bar plot.
Answer
import pandas as pd
import [Link] as plt
data = {"Stream": ["Science", "Commerce", "Hum
"Number of Courses": [12, 10, 15]
}
df = [Link](data)
df.to_csv('du_colleges.csv', index=False)
df = pd.read_csv("du_colleges.csv")
[Link](df["Stream"], df["Number of Courses"])
[Link]("Stream")
[Link]("Number of Courses")
[Link]("Number of Courses in Each Stream")
[Link]()
Output
Question 20
What is a histogram? How do you create
histograms in Python?
Answer
A histogram is a summarization tool for discrete
or continuous data, providing a visual
interpretation of numerical data by showing the
number of data points that fall within a specified
range of values.
The hist() function of the Pyplot module is
used to create and plot a histogram from a given
sequence of numbers. The syntax for using the
hist() function in Pyplot is as follows:
[Link](x, bins = None,
cumulative = False, histtype = 'bar', align =
'mid', orientation = 'vertical', ) .
Question 21
What are the various types of histograms that
can be created through hist() function?
Answer
The hist() function in Matplotlib's Pyplot
module allows creating various types of
histograms. These include the default bar
histogram (histtype='bar'), step histogram
(histtype='step'), stepfilled histogram
(histtype='stepfilled'), barstacked histogram
(histtype='barstacked').
Question 22
When should you create histograms and when
should you create bar charts to present data
visually?
Answer
Histograms are great for displaying specific
ranges of values and are ideal for visualizing the
results of continuous data, such as the ages of
students in a class. Bar charts, on the other
hand, are effective for comparing categorical or
discrete data across different categories or
groups, such as comparing the sales
performance of different products.
Question 23(i)
Given the following set of data:
Weight measurements for 14 values of muffins (in
grams)
78, 72, 69, 81, 63, 67, 65
79, 74, 71, 83, 71, 79, 80
Create a simple histogram from the above data.
Answer
import [Link] as plt
weights = [78, 72, 69, 81, 63, 67, 65, 79, 74,
[Link](weights)
[Link]('Weight Distribution of muffins')
[Link]()
Output
Question 23(ii)
Given the following set of data:
Weight measurements for 14 values of muffins (in
grams)
78, 72, 69, 81, 63, 67, 65
79, 74, 71, 83, 71, 79, 80
Create a horizontal histogram from the above
data.
Answer
import [Link] as plt
weights = [78, 72, 69, 81, 63, 67, 65, 79, 74,
[Link](weights, orientation = 'horizontal')
[Link]('Weight Distribution of muffins')
[Link]()
Output
Question 23(iii)
Given the following set of data:
Weight measurements for 14 values of muffins (in
grams)
78, 72, 69, 81, 63, 67, 65
79, 74, 71, 83, 71, 79, 80
Create a step type of histogram from the above
data.
Answer
import [Link] as plt
weights = [78, 72, 69, 81, 63, 67, 65, 79, 74,
[Link](weights, histtype = 'step')
[Link]('Weight Distribution of muffins')
[Link]()
Output
Question 23(iv)
Given the following set of data:
Weight measurements for 14 values of muffins (in
grams)
78, 72, 69, 81, 63, 67, 65
79, 74, 71, 83, 71, 79, 80
Create a cumulative histogram from the above
data.
Answer
import [Link] as plt
weights = [78, 72, 69, 81, 63, 67, 65, 79, 74,
[Link](weights, cumulative = True)
[Link]('Weight Distribution of muffins')
[Link]()
Output
Question 24
Kritika was asked to write the names of a few
libraries in Python used for data analysis and one
method of each. Help her write at least 3 libraries
and their methods.
Answer
The three libraries in Python used for data
analysis are as follows:
1. Pandas library — array() function
2. NumPy library — DataFrame() function
3. Matplotlib library — plot() function
ICSE/ISC/CBSE PRACTICE TESTS COMPANY
Class - 9 ICSE Mathematics Sample Paper Tests Pricing
Class - 9 ICSE Biology Practice Tests About Us
Class - 10 ICSE Mathematics Practice Tests Contact Us
Class - 10 ICSE Mathematics Sample Paper Tests Privacy Policy
Class - 10 ICSE Biology Sample Paper Tests Terms of Service
Class - 10 ICSE Computer Applications Sample Paper Tests
Class - 12 CBSE Computer Science Practice Tests
Class - 12 CBSE Computer Science Sample Paper Tests
Class - 12 CBSE Informatics Practices Sample Paper Tests
ICSE/ISC TEXTBOOK SOLUTIONS
Class - 6 Concise Biology Selina Solutions
Class - 6 Veena Bhargava Geography Solutions
Class - 6 Effective History & Civics Solutions
Class - 7 Concise Physics Selina Solutions
Class - 7 Concise Chemistry Selina Solutions
Class - 7 Dalal Simplified Middle School Chemistry Solutions
Class - 7 Concise Biology Selina Solutions
Class - 7 Living Science Biology Ratna Sagar Solutions
Class - 7 Around the World Geography Solutions
Class - 7 Veena Bhargava Geography Solutions
Class - 7 Effective History & Civics Solutions
Class - 8 Concise Physics Selina Solutions
Class - 8 Concise Chemistry Selina Solutions
Class - 8 Dalal Simplified Middle School Chemistry Solutions
Class - 8 Concise Biology Selina Solutions
Class - 8 Living Science Biology Ratna Sagar Solutions
Class - 8 Around the World Geography Solutions
Class - 8 Veena Bhargava Geography Solutions
Class - 8 Effective History & Civics Solutions
Class - 8 Kips Logix Computers Solutions
Class - 9 Concise Physics Selina Solutions
Class - 9 Concise Chemistry Selina Solutions
Class - 9 Dalal Simplified ICSE Chemistry Solutions
Class - 9 Concise Biology Selina Solutions
Class - 9 Total Geography Morning Star Solutions
Class - 9 Veena Bhargava Geography Solutions
Class - 9 Total History & Civics Solutions
Class - 9 Kips Logix Computers Solutions
Class - 10 Concise Physics Selina Solutions
Class - 10 Concise Chemistry Selina Solutions
Class - 10 Dalal Simplified ICSE Chemistry Solutions
Class - 10 Concise Biology Selina Solutions
Class - 10 Total Geography Morning Star Solutions
Class - 10 Veena Bhargava Geography Solutions
Class - 10 Total History & Civics Solutions
Class - 10 Sumita Arora ICSE Computers Solutions
Class - 10 Kips Logix Computers Solutions
ICSE/ISC SOLVED QUESTION PAPERS
Class - 10 ICSE Maths Solved Competency Focused Questions
Class - 10 ICSE Biology Solved Competency Focused Questions
ICSE Class 10 Computers Solved 10 Yrs Question Papers
Sample Papers ICSE Class 10 Computer Applications
ICSE Class 10 Physics Solved 10 Yrs Question Papers
Sample Papers ICSE Class 10 Physics
ICSE Class 10 Chemistry Solved 10 Yrs Question Papers
Sample Papers ICSE Class 10 Chemistry
ICSE Class 10 Biology Solved 10 Yrs Question Papers
Sample Papers ICSE Class 10 Biology
ICSE Class 10 Maths Solved Previous Yrs Question Papers
Class - 12 ISC Computer Science Solved Practical Papers
Class - 10 CBSE Computer Applications Solved Question Papers
Class - 10 CBSE Computer Applications Solved Sample Papers
Class - 10 CBSE Science Solved Question Papers
Class - 12 CBSE Computer Science Solved Question Papers
Class - 12 CBSE Informatics Practices Solved Question Papers
CBSE TEXTBOOK SOLUTIONS
Class - 8 NCERT Science Solutions
Class - 9 NCERT Mathematics Solutions
Class - 9 NCERT Science Solutions
Class - 9 NCERT Geography Contemporary India 1 Solutions
Class - 9 NCERT History India & Contemporary World 1 Solutions
Class - 9 Sumita Arora Computer Code 165 Solutions
Class - 9 Kips Cyber Beans Computer Code 165 Solutions
Class - 10 NCERT Mathematics Solutions
Class - 10 NCERT Science Solutions
Class - 10 NCERT Geography Contemporary India 2 Solutions
Class - 10 NCERT History India & Contemporary World 2 Solutions
Class - 10 NCERT Democratic Politics 2 (Civics) Solutions
Class - 10 NCERT Economic Development Solutions
Class - 10 Sumita Arora Computer Code 165 Solutions
Class - 10 Kips Cyber Beans Computer Code 165 Solutions
Class - 11 CBSE Sumita Arora Python Solutions
Class - 11 CBSE Preeti Arora Python Solutions
Class - 11 CBSE Informatics Practices Preeti Arora Solutions
Class - 12 CBSE Sumita Arora Python Solutions
Class - 12 CBSE Preeti Arora Python Solutions
Class - 12 NCERT Computer Science Solutions
Class - 12 CBSE Informatics Practices Sumita Arora Solutions
Class - 12 CBSE Informatics Practices Preeti Arora Solutions
STUDYLIST
Java Pattern Programs
Java Series Programs
Java Number Programs (ICSE Classes 9 / 10)
Java Number Programs (ISC Classes 11 / 12)
Output Questions for Class 10 ICSE Computer Applications
Algorithms & Flowcharts for ICSE Computers
ICSE Class 8 Computers Differentiate Between the Following
CBSE Class 12 Computer Science Important Output Questions
CBSE Class 12 Computer Science Assertion Reason Questions
CBSE Class 12 Computer Science File Handling Questions
Copyright © KnowledgeBoat 2025