Unit 11: Data visualization - Practice Quiz
1
Which Python module is commonly imported as plt for data visualization?
matplotlib.array
matplotlib.pyplot
matplotlib.data
matplotlib.table
2
Which statement correctly imports matplotlib.pyplot using its conventional alias?
from matplotlib import data
from pyplot import matplotlib
import matplotlib.pyplot as mpl
import matplotlib.pyplot as plt
3 Which function displays a completed Matplotlib figure on the screen?
plt.view()
plt.show()
plt.print()
plt.open()
4 Which Matplotlib function creates a basic line plot?
plt.scatter()
plt.plot()
plt.bar()
plt.hist()
5 What is a line plot commonly used to show?
6 Which function adds a label to the horizontal axis of a line plot?
plt.legend()
plt.xlabel()
plt.ylabel()
plt.title()
7 What is a subplot in Matplotlib?
8 Which function can create a figure and multiple axes at the same time?
plt.savefig()
plt.subplots()
plt.xlabel()
plt.legend()
9
In plt.subplots(2, 2), how many subplots are created?
10 Which function creates a vertical bar chart in Matplotlib?
plt.pie()
plt.bar()
plt.boxplot()
plt.plot()
11 A bar chart is most suitable for comparing which type of data?
12 Which function creates horizontal bars in Matplotlib?
plt.hist()
plt.hlines()
plt.barh()
plt.hbar()
13 Which Matplotlib function creates a histogram?
plt.pie()
plt.hist()
plt.plot()
plt.bar()
14 What do the bars in a histogram usually represent?
15
What does the bins argument control in a histogram?
16 Which function creates a box and whisker plot?
plt.boxplot()
plt.barh()
plt.scatter()
plt.subplots()
17 What does the line inside the box of a standard box plot represent?
18 Which function creates a scatter plot in Matplotlib?
plt.hist()
plt.boxplot()
plt.scatter()
plt.barh()
19 What is a scatter plot commonly used to examine?
20 Which Matplotlib function creates a pie chart?
plt.pie()
plt.bar()
plt.hist()
plt.plot()
21 Which code correctly imports Matplotlib's plotting interface using its conventional alias?
import pyplot.matplotlib as plt
from matplotlib import plt
import matplotlib as pyplot
import matplotlib.pyplot as plt
22 A script creates a plot successfully but no window appears when it is run outside a notebook. Which statement should normally be added after the plotting commands?
plt.render()
plt.open()
plt.display()
plt.show()
23
What does the following code plot?
plt.plot([1, 2, 3], [2, 4, 1], "r--o")
24 A program must plot temperature values against the corresponding days and include a legend. Which code is correct?
plt.plot(days, temperatures); plt.label("Temperature")
plt.plot(days, temperatures, label="Temperature"); plt.legend()
plt.line(days, temperatures, legend="Temperature"); plt.show()
plt.plot(temperatures, days, title="Temperature"); plt.legend()
25
Given x = [1, 2, 3, 4], which value of y can be used directly in plt.plot(x, y)?
[2, 4, 6, 8]
[[2, 4], [6, 8]]
[2, 4, 6]
[2, 4, 6, 8, 10]
26
What is selected by plt.subplot(2, 3, 4)?
27
After fig, axes = plt.subplots(2, 2), which expression accesses the subplot in the second row and first column?
axes[1, 0]
axes[1, 1]
axes[0, 1]
axes[2, 1]
28 Labels in a figure containing several subplots overlap one another. Which Matplotlib call is designed to improve their spacing automatically?
plt.tight_layout()
plt.equal_layout()
plt.fixed_layout()
plt.merge_layout()
29
A store wants to compare sales for the categories Books, Games, and Music. Which command produces an appropriate vertical bar chart?
plt.scatter(categories, sales)
plt.plot(categories, sales)
plt.bar(categories, sales)
plt.hist(categories, sales)
30
For grouped bars, the first series uses positions x and width w. Which positions should the second series use to place its bars immediately beside the first series?
x + 2*w
x - w
x + w
x - 2*w
31
Which function should replace plt.bar() when category names are long and horizontal bars would improve readability?
plt.barx()
plt.barh()
plt.horizontal()
plt.hbar()
32
What is the main effect of changing bins=5 to bins=20 in plt.hist(data, bins=...) while keeping the data unchanged?
33
Consider data = [1, 2, 2, 3, 8, 9] and bins with edges [0, 5, 10]. How many observations fall into the first bin?
34 Two datasets contain different numbers of observations. Which argument helps compare their histogram shapes using normalized area rather than raw counts?
scale="equal"
normalize="count"
frequency=True
density=True
35 In a standard box plot, what does the line drawn inside the box represent?
36 For a box plot, and . Using the rule, which value would be plotted as an upper outlier?
37 A scatter plot shows heavy overlap among points. Which modification most directly makes dense regions easier to observe without changing point positions?
aspect="equal"
alpha=0.3
linewidth=3
marker="s"
38
In plt.scatter(x, y, s=sizes, c=values, cmap="viridis"), what does cmap="viridis" control?
values map to point colors
sizes map to point areas
39
Given sizes = [50, 30, 20], which explode argument separates only the second slice from the center?
explode=(0, 0.1, 0)
explode=(0.1, 0, 0)
explode=(0, 0, 0.1)
explode=(0.1, 0.1, 0)
40 Which argument displays each pie slice's percentage with one digit after the decimal point?
autopct="%1.1f%%"
percent="%1.1f%%"
labels="%1.1f%%"
autopct="%1f%"
41
Consider: fig, (ax1, ax2) = plt.subplots(1, 2); plt.sca(ax1); ax2.plot([0, 1], [0, 1]); plt.title("T"). Which axes receives the title?
ax2, because plotting through an axes object makes it current
ax1, because calling ax2.plot does not change pyplot's current axes
plt.title requires an explicit axes argument
42
After fig = plt.figure() and plt.close(fig), assuming another reference to fig is retained, which statement is correct?
plt.get_fignums(), but fig remains usable
43
What visible result is produced by plt.plot([0, 1, 2, 3], [4, np.nan, 6, 7]) under normal linear-axis settings?
44
Given x = [0, 2, 1, 3] and y = [0, 4, 1, 9], what does plt.plot(x, y) do?
x but leaves y in its original order
x is not monotonically increasing
x before drawing the line
45
What is the final x-axis range after ax.plot([0, 1], [0, 1]); ax.set_xlim(0, 10); ax.plot([20, 30], [2, 3])?
46
What does fig, axs = plt.subplots(1, 1, squeeze=False) guarantee about axs?
(1,)
Axes object
Axes object with no array dimensions
(1, 1)
47
Consider fig, (a, b) = plt.subplots(2, 1, sharex=True); a.set_xlim(2, 8); b.set_xlim(0, 5). What are the final x limits?
a has , while b retains automatic limits
a has , while b has
48
What happens when plt.bar(["A", "A", "B"], [2, 5, 3]) is executed?
ValueError occurs because categorical labels must be unique
A is renamed automatically to create a separate category
A values are combined into one bar of height
A bars occupy the same categorical x-coordinate and overlap
49
For a = [3, -2, 4] and b = [-1, 5, -3], the calls ax.bar(x, a) and ax.bar(x, b, bottom=a) are made. What are the y-coordinates of the second bars' top boundaries?
50
With ax.bar([2], [5], width=-0.8, align="edge"), which horizontal interval does the bar occupy?
51
What bin counts are returned by plt.hist([0, 1, 2], bins=[0, 1, 2])?
52
For data [0.2, 0.8, 2, 3], bins [0, 1, 4], and density=True, what are the two histogram heights?
53
Data [0.2, 0.8, 1.5] have weights [1, 3, 2]. With bins [0, 1, 3] and density=True, what heights are produced?
54
Using the default whis=1.5, where does the upper whisker end for the data [1, 2, 3, 4, 100]?
55
For [1, 2, 3, 4, 100], what changes when showfliers=False is passed while the default whis is retained?
56
In plt.scatter, marker size s is measured in points squared. Ignoring edge effects, how must s change to double a marker's diameter?
s by
s
s
s by
57
What is the likely interpretation of ax.scatter([0, 1, 2], [1, 2, 3], c=(0.2, 0.4, 0.6), cmap="viridis")?
(0.2, 0.4, 0.6)
c accepts only color names or hexadecimal strings
58
What total angular span is drawn by ax.pie([0.2, 0.3], normalize=False)?
59
For ax.pie([1, 3], startangle=90, counterclock=False), at what angle is the midpoint ray of the first wedge?
60
What does explode=[0.2, 0] do in ax.pie([1, 1], explode=[0.2, 0])?
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →