Data Visualization
Data Visualization
Question 1
Answer
Data visualization basically refers to the graphical or visual representation of information and
data using visual elements like charts, graphs, maps and so forth.
Question 2
Answer
The Python library generally used for data visualization is Matplotlib library.
Question 3
Answer
Yes, Pyplot is a Python library. Pyplot is a collection of methods within matplotlib library which
allows user to construct 2D plots easily and interactively.
Question 4
Name the function you will use to create a horizontal bar chart.
Answer
Question 5
Which argument will you provide to change the following in a line chart ?
Answer
(i) For changing the width of the line, we use the linewidth argument with the plot() function
as: <[Link]>.plot(<data1>, [,data2], linewidth = <width> )
(ii) For changing the color of the line, we use the color argument with the plot() function
as: <[Link]>.plot(<data1>, [,data2], <color code>)
Question 6
What is a marker ? How can you change the marker type and color in a plot ?
Answer
The data points being plotted on a graph/chart are called markers. To change the marker type and
color, we use following additional optional arguments in plot function : marker = <valid
marker type>, markeredgecolor = <valid color>.
Question 7
Answer
Question 8
Answer
No, bar charts and histograms are not same. A bar chart or bar graph is a chart or graph that
presents categorical data with rectangular bars with heights or lengths proportional to the values
that 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.
Question 9
Name various types of histogram plots that you can create using Pyplot.
Answer
The types of histogram plots that we can create using Pyplot are cumulative histogram, step type
histogram, stacked bar type histogram, horizontal histogram.
Question 10
Question 11
Answer
The box plot is used to show the range and the middle half of the ranked data.
Question 12
Answer
Question 1
1. csv
2. matplotlib
3. numpy
4. pandas
Answer
matplotlib
Question 2
1. seaborn
2. plotly
3. ggplot
4. matplotlib
Answer
matplotlib
Reason — PyPlot is an interface of Python's Matplotlib library that allows users to construct 2D
plots easily and interactively.
Question 3
For 2D plotting using a Python library, which library interface is often used ?
1. seaborn
2. plotly
3. matplotlib
4. [Link]
Answer
[Link]
Reason — The [Link] interface is commonly used for 2D plotting in Python using
the Matplotlib library.
Question 4
1. histogram
2. statistical
3. pie
4. box
Answer
statistical, box
Reason — Pie charts and histograms are valid chart types used for data visualization. Statistical
and box plots are not valid chart types.
Question 5
1. plot()
2. bar()
3. line()
4. pie()
Answer
line()
Reason — The line() function is not a valid plotting function of Pyplot. In Matplotlib's Pyplot
module, the correct function for creating line plots is plot().
Question 6
Which of the following plotting functions does not plot multiple data series ?
1. plot()
2. bar()
3. pie()
4. barh()
Answer
pie()
Reason — The pie() function in Matplotlib's Pyplot module can plot only one data sequence.
On the other hand, functions like plot(), bar(), and barh() can plot multiple data series in a
single chart.
Question 7
The plot which tells the trend between two graphed variables is the ............... graph/chart.
1. line
2. scatter
3. bar
4. pie
Answer
line
Reason — A line chart or line graph is a type of chart which displays information as a series of
data points called "markers" connected by straight line segments.
Question 8
The plot which tells the correlation between two variables which may not be directly related
is ............... graph/chart.
1. line
2. scatter
3. bar
4. pie
Answer
scatter
Reason — A scatter chart is a graph of plotted points on two axes that show the relationship
between two sets of data.
Question 9
1. quartile
2. histogram
3. mean
4. median
Answer
histogram
Question 10
A visual representation of the statistical five number summary of a given dataset is known
as ............... .
1. histogram
2. frequency distribution
3. box plot
4. frequency polygon
Answer
box plot
Reason — A box plot provides a visual representation of the statistical five-number summary of
a given dataset. It includes the highest and lowest numbers, the median, and the upper and lower
quartiles.
Question 11
1. line()
2. plot()
3. chart()
4. plotline()
Answer
plot()
Reason — The plot() function is used to create a line chart or line graph.
Question 12
1. plot()
2. bar()
3. plotbar()
4. barh()
Answer
bar(), barh()
Reason — With Pyplot, a bar chart is created using bar() and barh() functions.
Question 13
1. plot()
2. bar()
3. plotbar()
4. barh()
Answer
bar()
1. plot()
2. bar()
3. plotbar()
4. barh()
Answer
barh()
Question 15
To specify the style of line as dashed, which argument of plot() needs to be set ?
1. line
2. width
3. style
4. linestyle
Answer
linestyle
Reason — To specify the style of the line as dashed in Matplotlib's plot() function, we need to
set the linestyle argument to 'dashed'.
Question 16
1. points
2. pointers
3. marks
4. markers
Answer
markers
Reason — The data points being plotted on a graph/chart are called markers.
Question 17
A ............... graph is a type of chart which displays information as a series of data points
connected by straight line segments.
1. line
2. bar
3. pie
4. box plot
Answer
line
Reason — A line chart or line graph is a type of chart which displays information as a series of
data points called "markers" connected by straight line segments.
Question 18
1. marker
2. linestyle
3. markeredgecolor
4. linewidth
Answer
linestyle
Question 19
1. size
2. s
3. marker
4. markersize
Answer
s
Reason — The s argument in scatter() is used to specify the size of data points.
Question 20
1. thick
2. thickness
3. width
4. barwidth
Answer
width
Reason — The width argument allows to control the thickness of the bars in a bar chart created
using the bar() function in Matplotlib.
Question 21
To change the width of bars in a bar chart, which of the following arguments with a float value is
used ?
1. hwidth
2. width
3. breath
4. barwidth
Answer
width
Reason — The width argument with a float value is used to change the width of bars in a bar
chart created using the bar() function in Matplotlib.
Question 22
1. title()
2. plottitle()
3. graphtitle()
4. all of these
Answer
title()
Reason — The title() function sets the title of the plot in Matplotlib.
Question 23
1. [Link]()
2. [Link]()
3. [Link]()
4. [Link]()
Answer
[Link]()
Reason — The [Link]() command is used in Matplotlib's Pyplot module to give a heading
or title to a graph.
Question 24
Which function would you use to set the limits for x-axis of the plot ?
1. limits()
2. xlimits()
3. xlim()
4. lim()
Answer
xlim()
Reason — The xlim() function is used to set the limits for the x-axis of a plot in Matplotlib.
Question 25
1. display()
2. show()
3. legend()
4. legends()
Answer
legend()
Reason — The legend() function in Matplotlib's Pyplot module is used to show legends in a
plot.
Question 26
Which argument must be set with plotting functions for legend() to display the legends ?
1. data
2. label
3. name
4. sequence
Answer
label
Reason — The label argument must be set with plotting functions for the legend() function to
display the legends correctly.
Question 27
1. histo()
2. histogram()
3. hist()
4. histtype
Answer
hist()
Question 28
1. histt
2. histtype
3. type
4. barstacked
Answer
histtype
Reason — The histtype argument in Matplotlib's hist() function is used to create a stacked
bar type histogram. Setting histtype = 'barstacked' creates a histogram where bars for each
bin are stacked on top of each other, representing different categories or subgroups within the
data.
Question 29
Which of the following functions can plot only one data series ?
1. plot()
2. bar()
3. boxplot()
4. pie()
Answer
pie()
Reason — The pie() function in Matplotlib's Pyplot module can plot only one data series. On
the other hand, functions like plot(), bar(), and boxplot() can plot multiple data series in a
single chart.
Question 30
1. label
2. autopct
3. explode
4. wedge
Answer
explode
Reason — The explode argument is used in pie charts to visually separate one or more wedges
from the rest of the pie chart.
Question 31
Which argument should be set to display percentage share of each pie on a pie chart ?
1. label
2. autopct
3. explode
4. wedge
Answer
autopct
Question 32
1. box()
2. plot()
3. boxplot()
4. showbox()
Answer
boxplot()
Question 33
1. fill
2. box
3. patch_artist
4. patch
Answer
patch_artist
Reason — The patch_artist argument in the boxplot() function is used to create a filled box
plot. When set to True, it fills the boxes of the box plot with a color, making them more visually
distinct.
Fill in the Blanks
Question 1
A histogram is a plot that shows the underlying frequency distribution of a set of continuous
data.
Question 2
Question 3
Question 4
Question 5
Question 6
Question 7
Question 8
The linewidth argument of plot() specifies the width for the line.
Question 9
Question 10
Question 11
Question 13
Question 14
Question 15
Question 16
Question 17
Using Python Matplotlib histogram can be used to count how many values fall into each
interval. (line plot / bar graph / histogram)
True/False Questions
Question 1
Answer
True
Question 2
Answer
False
Reason — The statement import [Link] is the valid and commonly used way to
import the PyPlot submodule from the Matplotlib library.
Question 3
Answer
True
Question 4
Answer
False
Reason — By default, a pie chart is printed in an elliptical or oval shape. It can be changed to a
circle by using the axis() function of Pyplot and passing the 'equal' argument to it.
Question 5
Answer
False
Reason — In Matplotlib's Pyplot library, the function used to plot a line chart is plot().
Question 6
Answer
True
Reason — In Matplotlib's Pyplot library, the function used to plot a line chart is plot().
Question 7
A bar chart can be plotted using pyplot library's bar() function.
Answer
True
Reason — In Matplotlib's Pyplot library, the function used to plot a bar chart is bar().
Question 8
Answer
True
Reason — The barh() function in Matplotlib's Pyplot library is used to create horizontal bar
charts.
Question 9
It is not possible to plot multiple series of values in the same bar graph.
Answer
False
Reason — It is possible to plot multiple series of values in the same bar graph using Matplotlib's
Pyplot library because the bar() and barh() functions support handling multiple datasets.
Question 10
Answer
True
Reason — A standard marker for representing missing or non-number data in Python libraries is
NaN (Not a Number).
Question 11
If the linestyle argument is missing along with markerstyle-string in a plot(), a scatter type chart
get created.
Answer
True
Reason — When both the linestyle argument and the marker argument (markerstyle-string)
are not specified in the plot() function, the resulting chart can resemble a scatter plot. In this
case, the points will be plotted without connected lines, similar to how a scatter plot displays data
points.
Question 12
Answer
False
Reason — The bar() function in Matplotlib's Pyplot library can create vertical bar charts, while
the barh() function creates horizontal bar charts.
Question 13
Answer
False
Reason — The pie() function in Matplotlib's Pyplot module can plot only one data series.
Question 14
The plot is always as per the data series being plotted irrespective of the xlim().
Answer
False
Reason — The plot appearance can be affected by the data series being plotted, but it can also be
influenced by functions such as xlim() which determine the range of values shown on the x-
axis.
Question 15
Answer
True
Reason — When a frequency polygon is drawn manually, it is based on the data that would be
used to create a histogram.
Question 16
(c) Data Visualization makes complex data more accessible, understandable, and usable.
Answer
Reason — To create charts and visualizations in Python, we need to import libraries such as
Matplotlib.
Question 1
Answer
Explanation
The Matplotlib library is used for data visualization in Python, providing a variety of tools and
functionalities for creating different types of plots, charts, and graphs. The Pyplot module, which
is a collection of methods within the Matplotlib library, allows users to construct 2D plots easily
and interactively.
Question 2
Assertion. A scatter chart simply plots the data points on a chart to show the trend in the data.
Reason. A line chart connects the plotted data points with a line.
Answer
Explanation
The scatter chart is a graph of plotted points on two axes that show the relationship between two
sets of data. On the other hand, a line chart, or line graph, is a type of chart that displays
information as a series of data points called 'markers' connected by straight line segments.
Question 3
Assertion. Both scatter() and plot() functions of PyPlot can create scatter charts.
Reason. The plot() function can create line charts as well as scatter charts.
Answer
Explanation
Both the scatter() and plot() functions in Pyplot can create scatter charts.
The plot() function in Pyplot can create both line charts and scatter charts. When specifying
marker styles without providing a linestyle argument, the plot() function will create a scatter
chart.
Question 4
Assertion. For the same sets of data, you can create various charts using plot(), scatter(), pie(),
bar() and barh().
Reason. All the data sets of a plot(), scatter(), bar() cannot be used by pie() ; it will work with
only a single set of data.
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
Explanation
We can create various charts using plot(), scatter(), bar(), and barh() for the same
datasets, but not using pie(). The pie() function specifically works with a single set of data,
whereas the other functions can handle multiple datasets or series.
Question 5
Reason. The boxplot() function can plot the highest and lowest numbers of a data range, its
median along with the upper and lower quartiles.
Answer
Explanation
The five-point statistical summary of a dataset can be visually represented through a box plot. A
box plot is used to display the range and middle half of ranked data. It uses five important
numbers from the data range: the extremes (highest and lowest numbers), the median, and the
upper and lower quartiles, comprising the five-number statistical summary.
Question 6
Assertion. Line graph is a tool for comparison and is created by plotting a series of several
points and connecting them with a straight line.
Reason. You should never use a line chart when the chart is in a continuous data set.
Answer
Explanation
A line graph is a tool for comparison, created by plotting a series of data points called 'markers'
and connecting them with straight lines. This makes it easier to compare different data points and
observe patterns. Line charts are suitable for continuous data sets, displaying information as a
series of data and not restricted to discontinuous data sets.
Question 1
Answer
Question 2
Answer
Question 3
(d) histogram
(j) boxplot
(g) pie chart
Answer
Question 4
Answer
A line chart, or line graph, is a type of chart that displays information as a series of data points
called 'markers' connected by straight line segments.
Question 5
Answer
The scatter chart is a graph of plotted points on two axes that show the relationship between two
sets of data. With a scatter plot, a mark or marker (usually a dot or small circle), represents a
single data point. With one mark (point) for every data point a visual distribution of the data can
be seen. Depending on how tightly the points cluster together, we may be able to discern a clear
trend in the data.
The difference is that with a scatter plot, the decision is made from the data points such that the
individual points should not be connected directly together with a line but, instead express a
trend.
Question 6
Answer
A pie chart is used to show parts in relation to the whole, often representing percentage shares
and numerical proportions.
Question 7
What is a bar chart ? How is it useful as compared to the line chart ?
Answer
A bar graph / bar chart is a graphical display of data using bars of different heights.
Compared to a line chart, which connects data points with lines, a bar chart is useful for
comparing discrete categories rather than showing continuous trends over time. Bar charts are
effective for highlighting differences in values between categories and are particularly useful
when dealing with categorical data or comparing data across different groups or time periods.
Question 8
Answer
Question 9
Answer
Box plots are suitable for visualizing the spread of data, identifying outliers, comparing data
distribution between different groups or categories, and assessing symmetry in a dataset.
Question 10
Answer
Question 11
Name the function to label axes.
Answer
The functions to label axes in a plot using Matplotlib's Pyplot library are xlabel() for the x-axis
and ylabel() for the y-axis.
Question 12
Answer
The function title() in Matplotlib's Pyplot library is used to add a title to a plot.
Question 13
Answer
The figure() function in Matplotlib's Pyplot library is used to set figure size of a plot.
Question 14
Answer
The function to set limits for the axes in a plot using Matplotlib's Pyplot library is xlim() for the
x-axis and ylim() for the y-axis.
Question 15
Answer
The legend() function in Matplotlib's Pyplot library is used to display a legend on the plot.
Question 16
Answer
The functions to add ticks on axes in a plot using Matplotlib's Pyplot library are xticks() for
the x-axis and yticks() for the y-axis.
Type B: Application Based Questions
Question 1
Answer
Patterns, trends and correlations that might go undetected in text-based data can be exposed and
recognized easier with data visualization techniques or tools such as line chart, bar chart, pie
chart, histogram, scatter chart etc. Thus with data visualization tools, information can be
processed in efficient manner and hence better decisions can be made.
Question 2
Answer
Python supports data visualizations by providing some useful libraries for visualization. Most
commonly used data visaulization library is matplotlib. Matplotlib is a Python library, also
sometimes known as the plotting library. The matplotlib library offers very extensive range of
2D plot types and output formats. It offers complete 2D support along with limited 3D graphic
support. It is useful in producing publication quality figures in interactive environment across
platforms. It can also be used for animations as well. There are many other libraries of Python
that can be used for data Visualization but matplotlib is very popular for 2D plotting.
Question 3
Answer
For data visualization in Python, the matplotlib library's Pyplot interface is used. Matplotlib is a
Python library that provides interfaces and functionalities for 2D graphics, similar to MATLAB's
in various forms. It offers both a quick way to visualize data in Python and creates publication-
quality figures in many formats. The Matplotlib library offers various named collections of
methods. Pyplot, as one such interface, enables users to construct 2D plots easily and
interactively.
Question 4
The popular ways of plotting data include line charts, bar charts, histograms, scatter plots, pie
charts, box plots.
Question 5
Answer
This function is used to create vertical bar This function is used to create horizontal bar
charts. charts.
The first sequence given in the bar() forms The first sequence given in the barh() forms
the x-axis and the second sequence values the y-axis and the second sequence values
are plotted on y-axis. are plotted on x-axis.
Question 6
Answer
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 7
What will happen if you use legend() without providing any label for the data series being
plotted ?
Answer
Using legend() function without labels results in default labels (e.g., "line 1," "line 2"). This
can confuse viewers as it lacks meaningful information about the data series being plotted.
Question 8
What do you understand by xlimit and ylimit ? How are these linked to data being plotted ?
Answer
The xlimit and ylimit determine which data values are visible on the x-axis and y-axis in a plot or
chart respectively. Only the data values that fall within these limits will be plotted. If no data
value maps to the specified x-limits or y-limits, nothing will show on the plot for that particular
axis range.
Question 9
(v) boxplot ?
Answer
(i) Line Chart — Use a line chart to show trends or changes over time. It's suitable for
displaying continuous data series and highlighting patterns or fluctuations.
(ii) Bar Chart — Use a bar chart to compare categories or groups. It's effective for displaying
discrete data and showing differences or relationships between items.
(iii) Scatter Chart — Use a scatter chart to visualize relationships between two variables. It's
helpful for identifying correlations or trends in data points.
(iv) Pie Chart — Use a pie chart to represent parts of a whole. It's useful for showing the
proportion or distribution of different categories within a dataset.
(v) Boxplot — The box plot is used to show the range and the middle half of ranked data while
identifying outliers or variability.
Question 10
A list namely temp contains average temperatures for seven days of last week. You want to see
how the temperature changed in 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 11
Answer
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 12
What are 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 13
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 14
Answer
A cumulative histogram is a graphical representation in which each bin displays the count of data
points within that bin as well as the counts of all smaller bins. The final bin in this histogram
indicates the total number of data points in the dataset.
Question 15
Answer
Question 16
Answer
The five-point summary is a descriptive statistics tool that provides a concise summary of the
distribution of a dataset. It consists of five important numbers of a data range:
Question 17
What is Boxplot ? How do you create it in Pyplot ?
Answer
A boxplot is a visual representation of the statistical five number summary of a given data set,
including the extremes (the highest and the lowest numbers), the median, the upper and lower
quartiles.
Question 1(a)
Execute the following codes and find out what happens ? (Libraries have been imported already ;
plt is the alias name for [Link])
A = [Link](2, 20, 2)
B = [Link](A)
[Link](A, B)
Will this code produce error ? Why/Why not ?
Answer
Executing the provided code will not produce an error. It will generate a plot of the logarithm of
A against A itself.
Output
Explanation
The line A = [Link](2, 20, 2) creates an array A using NumPy's arange() function. It
starts from 2, increments by 2, and includes values up to 20. This results in the array [2, 4, 6, 8,
10, 12, 14, 16, 18]. Next, the line B = [Link](A) calculates the natural logarithm of each
element in array A using NumPy's log() function and stores the results in array B.
Finally, [Link](A, B) plots the values in array A along the x-axis and the corresponding
values in array B along the y-axis using Matplotlib's plot() function.
Question 1(b)
Execute the following codes and find out what happens ? (Libraries have been imported already ;
plt is the alias name for [Link])
A = [Link](2, 20, 2)
B = [Link](A)
[Link](A, B)
Will this code produce error ? Why/Why not ?
Answer
Executing the provided code will not produce an error. However, the resulting plot might not be
as expected because the x-axis values are discrete and categorical, not continuous.
Output
Explanation
The line A = [Link](2, 20, 2) creates an array A using NumPy's arange() function. It
starts from 2, increments by 2, and includes values up to 20. This results in the array [2, 4, 6, 8,
10, 12, 14, 16, 18]. Next, the line B = [Link](A) calculates the natural logarithm of each
element in array A using NumPy's log() function and stores the results in array B.
Finally, [Link](A, B) creates a bar plot using Matplotlib's bar() function. It plots the values
in array A along the x-axis and the corresponding values in array B along the y-axis.
Question 1(c)
Execute the following codes and find out what happens ? (Libraries have been imported already ;
plt is the alias name for [Link])
Answer
The code will produce an error because the variable Y is not defined.
The corrected code is:
Output
Explanation
The line X = [Link](1, 18, 2.655) creates an array X using NumPy's arange() function.
It starts from 1, increments by 2.655, and generates values less than 18. The resulting array will
look like [1., 3.655, 6.31, 8.965, 11.62, 14.275, 16.93]. Next, the line B = [Link](X) calculates
the natural logarithm of each element in array X using NumPy's log() function. Finally, the
line [Link](X, Y) attempts to use Matplotlib's scatter() function to create a scatter
plot. However, Y is not defined in code, leading to a NameError.
Question 2
Output
Explanation
This code snippet uses Matplotlib to create a bar chart. The list Months contains the names of the
months ['Dec', 'Jan', 'Feb', 'Mar'], while the list Attendance holds corresponding attendance
values [70, 90, 75, 95]. The [Link]() function is then used to create a bar plot, where each bar
represents a month and its height corresponds to the attendance value. Finally, [Link]() is
called to display the plot.
Question 3
Write a program to add titles for the X-axis, Y-axis and for the whole chart in below code.
[Link]()
Output
Question 4
[Link](A, B) produces (A and B are the sequences same as created in question 1) chart as :
Write code to produce charts as shown below:
Answer
import numpy as np
import [Link] as plt
A = [Link](2, 20, 2)
B = [Link](A)
C = [Link](A) * 1.2
[Link](A, B)
[Link](A, C)
[Link]()
Output
import numpy as np
import [Link] as plt
A = [Link](2, 20, 2)
B = [Link](A)
C = [Link](A) * (-1.2)
[Link](A, B)
[Link](A, C)
[Link]()
Output
Question 5
Write suitable Python code to create 'Favourite Hobby' Bar Chart as shown below :
Also give suitable python statement to save this chart.
Answer
Output
Question 6
Consider the following graph. Write the Python code to plot it. Also add the Title, label for X
and Y axis.
Using the following data for plotting the graph
Output
Question 7(a)
a 52 340 890
b 64 480 560
c 78 688 1102
d 94 766 889
Write code to create a scatter chart from the 1990 and 2010 columns of dataframe df1.
Answer
import pandas as pd
import [Link] as plt
data = {'1990': [52, 64, 78, 94],
'2000': [340, 480, 688, 766],
'2010': [890, 560, 1102, 889]}
df1 = [Link](data, index=['a', 'b', 'c', 'd'])
[Link](df1['1990'], df1['2010'])
[Link]()
Output
Question 7(b)
a 52 340 890
b 64 480 560
c 78 688 1102
d 94 766 889
Write code to create a line chart from the 1990 and 2000 columns of dataframe df1.
Answer
import pandas as pd
import [Link] as plt
data = {'1990': [52, 64, 78, 94],
'2000': [340, 480, 688, 766],
'2010': [890, 560, 1102, 889]}
df1 = [Link](data, index=['a', 'b', 'c', 'd'])
[Link](df1['1990'], df1['2000'])
[Link]()
Output
Question 7(c)
a 52 340 890
b 64 480 560
c 78 688 1102
d 94 766 889
Write code to create a bar chart plotting the three columns of dataframe df1.
Answer
import [Link] as plt
data = {'1990': [52, 64, 78, 94],
'2000': [340, 480, 688, 766],
'2010': [890, 560, 1102, 889]}
df1 = [Link](data, index=['a', 'b', 'c', 'd'])
[Link](kind = 'bar')
[Link]()
Output
Question 8
The score of four teams in 5 IPL matches is available to you. Write a program to plot these in a
bar chart.
Answer
Output
Question 9
The score of a team in 5 IPL matches is available to you. Write a program to create a pie chart
from this data, showing the last match's performance as a wedge.
Answer
Output
Question 10
The prices of a stock for 3 months are given. Write a program to show the variations in prices for
each month by 3 lines on same line chart. Make sure to add legends and labels. Show grid also.
Answer
Output
Question 11
A distribution data stores about 1000 random number. Write a program to create a scatter chart
from this data with varying point sizes.
Answer
import numpy as np
import [Link] as plt
X = [Link](1, 100, size = (1000,))
Y = [Link](1, 100, size = (1000,))
sizes = [Link](10, 100, size=100)
[Link](X, Y, s = sizes, color = 'r')
[Link]()
Output
Question 12
Navya has started an online business. A list stores the number of orders in last 6 months. Write a
program to plot this data on a horizontal bar chart.
Answer
Output
Question 13(a)
78 72 69 81 63 67 65 75
79 74 71 83 71 79 80 69
Create a simple histogram from the above data.
Answer
Question 13(b)
78 72 69 81 63 67 65 75
79 74 71 83 71 79 80 69
Create a horizontal histogram from the above data.
Answer
Output
Question 13(c)
78 72 69 81 63 67 65 75
79 74 71 83 71 79 80 69
Create a step type of histogram from the above data.
Answer
Output
Question 13(d)
78 72 69 81 63 67 65 75
79 74 71 83 71 79 80 69
Create a cumulative histogram from the above data.
Answer
Output
Question 14(a)
Create an ndarray containing 16 values and then plot this array along with dataset of previous
question in same histogram, normal histograms.
Answer
import numpy as np
import [Link] as plt
weights = [78, 72, 69, 81, 63, 67, 65, 75, 79, 74, 71, 83, 71,
79, 80, 69]
random_array = [Link](16)
[Link](weights)
[Link](random_array)
[Link]('Normal Histograms')
[Link]()
Output
Question 14(b)
Create an ndarray containing 16 values and then plot this array along with dataset of previous
question in same histogram, cumulative histograms.
Answer
import numpy as np
import [Link] as plt
weights = [78, 72, 69, 81, 63, 67, 65, 75, 79, 74, 71, 83, 71,
79, 80, 69]
random_array = [Link](16)
[Link](weights, cumulative = True)
[Link](random_array, cumulative = True)
[Link]('Cumulative Histograms')
[Link]()
Output
Question 14(c)
Create an ndarray containing 16 values and then plot this array along with dataset of previous
question in same histogram, horizontal histograms.
Answer
import numpy as np
import [Link] as plt
weights = [78, 72, 69, 81, 63, 67, 65, 75, 79, 74, 71, 83, 71,
79, 80, 69]
random_array = [Link](16)
[Link](weights, orientation = 'horizontal')
[Link](random_array, orientation = 'horizontal')
[Link]('Horizontal Histograms')
[Link]()
Output
Question 15
Out of above plotted histograms, which ones can be used for creating frequency polygons ? Can
you draw frequency polygons from all the above histograms ?
Answer
Out of the above plotted histograms, none can be used for creating frequency polygons. We
cannot draw frequency polygons from all the above histograms because to construct a frequency
polygon, we need a step-type histogram. A frequency polygon is constructed by connecting the
midpoints of the tops of the bars of a histogram. Step-type histograms provide a clear outline to
draw these connections.
Question 16
Answer
import numpy as np
import pandas as pd
import [Link] as plt
weights = [78, 72, 69, 81, 63, 67, 65, 75, 79, 74, 71, 83, 71,
79, 80, 69]
[Link](figsize = (10, 5))
n, edges, p = [Link](weights, bins = 40, histtype = 'step')
m = 0.5 * (edges[1:] + edges[:-1])
m = [Link]()
l = len(m)
[Link](0, m[0] - 10)
[Link](m[l-1] + 10)
n = [Link]()
[Link](0, 0)
[Link](0)
[Link](m, n, '-^')
[Link]()
Output
Question 17(a)
63, 65, 67, 69, 69, 71, 71, 72, 74, 75, 78, 79, 79, 80, 81, 83
Create a horizontal boxplot.
Answer
Output
Question 17(b)
63, 65, 67, 69, 69, 71, 71, 72, 74, 75, 78, 79, 79, 80, 81, 83
Create a vertical boxplot.
Answer
Output
Question 17(c)
63, 65, 67, 69, 69, 71, 71, 72, 74, 75, 78, 79, 79, 80, 81, 83
Show means in the boxplot.
Answer
Output
Question 17(d)
63, 65, 67, 69, 69, 71, 71, 72, 74, 75, 78, 79, 79, 80, 81, 83
Create boxplot without the box.
Answer
Output
Question 18
Sina has created ordered set of data from the number of new customers registered on his online
service centre in last 20 months.
Write a program to plot this data on a filled boxplot with means shown.
Answer
Output