CHAPTER -3
WORKING WITH PYPLOT
TOPICS: BAR ,PIE,HISTOGRAM,BOXPLOT(REMAINING TOPICS CONTINUED)
NOTE:PART 1 POSTED ON APRIL 15
OBJECTIVE TYPE QUESTIONS
1)A ............... is a summarization tool for discrete or continuous data.
1. quartile
2. histogram
3. mean
4. median
2)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
3)Which of the following functions is used to create a line chart ?
1. line()
2. plot()
3. chart()
4. plotline()
4)Which of the following function will produce a bar chart ?
1. plot()
2. bar()
3. plotbar()
4. barh()
5)Which of the following function will create a horizontal bar chart ?
1. plot()
2. bar()
3. plotbar()
4. barh()
6)To specify the style of line as dashed, which argument of plot() needs to be set ?
1. line
2. width
3. style
4. linestyle
7)The data points plotted on a graph are called ............... .
1. points
2. pointers
3. marks
4. markers
8)In scatter(), which argument is used to specify the size of data points ?
1. size
2. s
3. marker
4. markersize
9)Which argument of bar() lets you set the thickness of bar ?
1. thick
2. thickness
3. width
4. barwidth
10)Which function lets you set the title of the plot ?
1. title()
2. plottitle()
3. graphtitle()
4. all of these
11)The command used to give a heading to a graph is ............... .
1. plt.show()
2. plt.plot()
3. plt.xlabel()
4. plt.title()
12.Which function would you use to set the limits for x-axis of the plot ?
1. limits()
2. xlimits()
3. xlim()
4. lim()
13.Which function is used to show legends ?
1. display()
2. show()
3. legend()
4. legends()
14.Which argument must be set with plotting functions for legend() to display the legends ?
1. data
2. label
3. name
4. sequence
15.Which function is used to create a histogram ?
1. histo()
2. histogram()
3. hist()
4. histtype
16.Which of the following functions can plot only one data series ?
1. plot()
2. bar()
3. boxplot()
4. pie()
17.Which function creates a box plot ?
1. box()
2. plot()
3. boxplot()
4. showbox()
18.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.
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.
SUBJECTIVE TYPE/PRACTICAL RELATED QUESTIONS
1.What is the role of legends in a graph/chart ?
When should you use
(i) a line chart
(ii) a bar chart
(iii) a scatter chart
(iv) pie chart
(v) boxplot ?
2.What is histogram ? How do you create histograms in Python ?
3.Write the output from the given python code :
import matplotlib.pyplot as plt
Months = ['Dec', 'Jan', 'Feb', 'Mar']
Attendance = [70, 90, 75, 95]
plt.bar(Months, Attendance)
plt.show()
4.Write suitable Python code to create 'Favourite Hobby' Bar Chart as shown below :
Also give suitable python statement to save this chart.
5.Given a data frame df1 as shown below :
1990 2000 2010
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.
6.Given a data frame df1 as shown below :
1990 2000 2010
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.
7.The score of four teams in 5 IPL matches is available to you. Display the output to plot these in a
bar chart.
import matplotlib.pyplot as plt
import numpy as np
Matches = ['Match 1', 'Match 2', 'Match 3', 'Match 4', 'Match 5']
Team_A = [150, 160, 170, 180, 190]
Team_B = [140, 150, 160, 170, 180]
Team_C = [130, 140, 150, 160, 170]
Team_D = [120, 130, 140, 150, 160]
X = np.arange(len(Matches))
plt.bar(Matches, Team_A, width = 0.15)
plt.bar(X + 0.15, Team_B, width = 0.15)
plt.bar(X + 0.30, Team_C, width = 0.15)
plt.bar(X + 0.45, Team_D, width = 0.15)
plt.xlabel('Matches')
plt.ylabel('Scores')
plt.title('IPL Scores')
plt.legend()
plt.show()
8.The score of a team in 5 IPL matches is available to you. Write the coding for the given chart from
this data, showing the last match's performance as a wedge.
9.Given the following set of data :
Weight measurements for 16 small orders of French-fries (in grams).
78 72 69 81 63 67 65 75
79 74 71 83 71 79 80 69
Create a simple histogram from the above data.
10.Display the output for the following code
import numpy as np
import matplotlib.pyplot as plt
weights = [78, 72, 69, 81, 63, 67, 65, 75, 79, 74, 71, 83, 71, 79, 80, 69]
random_array = np.arange(16)
plt.hist(weights, cumulative = True)
plt.hist(random_array, cumulative = True)
plt.title('Cumulative Histograms')
plt.show()