Class 12 Informatics Practices 065 Ch 3 Plotting with PyPlot Sumita Arora Book Exercise Solution

Type C: Practical/Knowledge-Based Questions

15. From the following ordered set of data:

63, 65, 67, 69, 69, 71, 71, 72, 74, 75, 78, 79, 79, 80, 81, 83

(a)  Create a horizontal boxplot.

(b)  Create a vertical boxplot.

(c)   Show means in the boxplot.

(d)  Create a boxplot without the box.

Ans:

import pandas as pd

import matplotlib.pyplot as plt

data = [63, 65, 67, 69, 69, 71, 71, 72, 74, 75, 78, 79, 79, 80, 81, 83]

#(a)  Create a horizontal boxplot.

plt.boxplot(data, vert=False)

plt.show()

#(b) Create a vertical boxplot.

plt.boxplot(data, vert = True)

plt.show()

#(c) Show means in the boxplot

plt.boxplot(data, showmeans=True)

plt.show()

#(d) Create boxplot without the box.

plt.boxplot(data, showbox=False)

plt.show()

Output:-

(a)

(b)

(c)

(d)

16. Sina has created an ordered set of data from the number of new customers registered on his online center in the last 20 months.  Write a program to plot this data on a filled boxplot with the means shown.

Ans:

import pandas as pd

import matplotlib.pyplot as plt

customers = [15,18,20,22,25,30,36,39,40,42,

45,49,50,53,57,59,60,62,65,70]

plt.boxplot(customers, showmeans=True, patch_artist=True)

plt.show