Unit 5: Data Visualization - Practice Quiz

CAP776 — Programming In Python 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is Matplotlib mainly used for in Python?

Introduction to Matplotlib Easy
A. Creating data visualizations
B. Writing web pages
C. Installing Python packages
D. Managing computer files

2 Which module is commonly imported to create basic plots with Matplotlib?

Introduction to Matplotlib Easy
A. matplotlib.files
B. matplotlib.tables
C. matplotlib.pyplot
D. matplotlib.data

3 What type of plot is best for showing a change in values over time?

Line plots Easy
A. Bar chart
B. Box plot
C. Pie chart
D. Line plot

4 Which Matplotlib function is commonly used to create a line plot?

Line plots Easy
A. makeline()
B. linechart()
C. plot()
D. drawline()

5 What is a bar chart commonly used to compare?

Bar charts Easy
A. Code comments
B. File sizes
C. Categories
D. Program errors

6 Which Matplotlib function creates a vertical bar chart?

Bar charts Easy
A. column()
B. bar()
C. vertical()
D. bars()

7 What does a scatter plot display?

Scatter plots Easy
A. Category rectangles
B. Individual data points
C. Parts of a whole
D. Connected time lines

8 Which Matplotlib function is used to create a scatter plot?

Scatter plots Easy
A. relationship()
B. scatter()
C. dots()
D. points()

9 What does a pie chart show?

Pie charts Easy
A. Values over time
B. Pairs of measurements
C. The spread of scores
D. Parts of a whole

10 Which Matplotlib function is commonly used to create a pie chart?

Pie charts Easy
A. pie()
B. slice()
C. sector()
D. circle()

11 What does a box-and-whisker plot help summarize?

Box-and-whisker plots Easy
A. The names of categories
B. The colors in an image
C. The distribution of data
D. The order of program steps

12 Which value is represented by the line inside the box of a box plot?

Box-and-whisker plots Easy
A. The minimum only
B. The median
C. The maximum only
D. The mean only

13 What is a histogram mainly used to show?

Histograms Easy
A. Parts of a circle
B. Frequency distribution
C. Connections between points
D. Category rankings

14 What are the intervals in a histogram commonly called?

Histograms Easy
A. Slices
B. Legends
C. Bins
D. Markers

15 Why are multiple subplots used in one figure?

Multiple subplots in one figure Easy
A. To convert charts into tables
B. To display several plots together
C. To remove all chart labels
D. To increase data values

16 Which Matplotlib function can create a figure and a set of subplots?

Multiple subplots in one figure Easy
A. manycharts()
B. subplots()
C. multiplot()
D. gridplots()

17 What is Seaborn?

Introduction to Seaborn Easy
A. A Python operating system
B. A database management tool
C. A text editing application
D. A Python visualization library

18 Which statement best describes Seaborn compared with Matplotlib?

Seaborn versus Matplotlib Easy
A. Matplotlib is only for databases
B. Seaborn provides a higher-level interface
C. Matplotlib cannot display figures
D. Seaborn cannot create charts

19 Which Seaborn function is commonly used to create a scatter plot?

Data visualization using Seaborn Easy
A. dotplotter()
B. relationshipplot()
C. scatterplot()
D. pointgraph()

20 What is the main purpose of a dashboard?

Introduction to data visualization tools for creating dashboards Easy
A. To replace all data collection
B. To hide charts from users
C. To display important information in one view
D. To store Python source code

21 Which code correctly uses Matplotlib's object-oriented interface to plot y against x and set the title?

Introduction to Matplotlib Medium
A. fig = plt.subplots(); fig.plot(x, y); plt.set_title('Trend')
B. fig, ax = plt.subplots(); fig.plot(x, y); fig.set_title('Trend')
C. fig, ax = plt.subplots(); ax.plot(x, y); ax.set_title('Trend')
D. ax = plt.figure(); ax.plot(x, y); ax.title('Trend')

22 A program must compare monthly sales for two years on the same axes. Which approach is most appropriate?

Line plots Medium
A. Call ax.plot() twice with different labels, then call ax.legend()
B. Call ax.bar() twice at identical positions, then call ax.grid()
C. Call ax.hist() twice with equal bins, then call ax.legend()
D. Call ax.scatter() twice with one shared marker, then call ax.grid()

23 What is the usual visual effect if a y sequence passed to plt.plot() contains a NaN value between two valid observations?

Line plots Medium
A. The entire line is removed from the axes
B. The missing value is automatically replaced by zero
C. The missing value is automatically linearly interpolated
D. The line usually contains a gap at that observation

24 Given x = np.arange(4) and width = 0.35, which positions produce side-by-side bars for two data series?

Bar charts Medium
A. x and x + 2 * width
B. x - width and x - width/2
C. x / width and x * width
D. x - width/2 and x + width/2

25 A chart has long category names that overlap when placed on the horizontal axis. Which Matplotlib function is the most direct alternative?

Bar charts Medium
A. plt.barh(categories, values)
B. plt.hist(categories, values)
C. plt.plot(categories, values)
D. plt.bar(categories, values)

26 In plt.scatter(x, y, s=population, c=income), what do s and c represent?

Scatter plots Medium
A. s controls line style and c controls axis color
B. s controls marker area and c controls marker color
C. s controls marker shape and c controls marker border
D. s controls transparency and c controls marker area

27 A scatter plot contains many overlapping points in the same region. Which change best reveals the density of overlapping observations?

Scatter plots Medium
A. Use a smaller marker size and set alpha below 1
B. Replace all coordinates with their overall averages
C. Connect every point using a solid line style
D. Use a larger marker size and set alpha to 1

28 Which argument adds percentage labels such as 25.0% to slices in a Matplotlib pie chart?

Pie charts Medium
A. format='%1.1f%%'
B. autopct='%1.1f%%'
C. labels='%1.1f%%'
D. percent='%1.1f%%'

29 A Matplotlib box plot uses the default rule whis=1.5. Which statement best describes a point above the upper whisker?

Box-and-whisker plots Medium
A. It lies above the arithmetic mean plus one standard deviation
B. It lies above the median plus exactly data units
C. It lies beyond the largest value within
D. It must be an incorrect value that should be deleted

30 Two groups have similar medians, but Group A has a much taller box than Group B. What does this most directly indicate?

Box-and-whisker plots Medium
A. Group A contains more observations
B. Group A has fewer possible outliers
C. Group A has a larger interquartile range
D. Group A has a larger arithmetic mean

31 The data are [0, 1, 2, 3, 4, 5]. Which call explicitly creates five equal-width bins covering the interval from 0 to 5?

Histograms Medium
A. plt.hist(data, bins=np.linspace(0, 5, 6))
B. plt.hist(data, bins=np.linspace(0, 5, 5))
C. plt.hist(data, bins=[0, 1, 2, 3, 4])
D. plt.hist(data, bins=np.arange(0, 5, 2))

32 When comparing samples of very different sizes, which option makes each histogram represent a probability density rather than raw counts?

Histograms Medium
A. Set cumulative=True
B. Set stacked=True
C. Set density=True
D. Set orientation='horizontal'

33 After fig, axes = plt.subplots(2, 3), which expression selects the axes in the second row and third column?

Multiple subplots in one figure Medium
A. axes[2, 2]
B. axes[1, 3]
C. axes[2, 3]
D. axes[1, 2]

34 Four vertically arranged time-series subplots should use the same x-axis scale and tick positions. Which construction is most suitable?

Multiple subplots in one figure Medium
A. plt.subplots(1, 4, constrained_layout=False)
B. plt.subplots(4, 1, sharex=True)
C. plt.subplots(4, 1, sharey=True)
D. plt.subplots(1, 4, squeeze=False)

35 Which statement correctly initializes a commonly used Seaborn theme before creating plots?

Introduction to Seaborn Medium
A. sns.create_theme(style='whitegrid')
B. sns.apply_style(theme='whitegrid')
C. sns.set_theme(style='whitegrid')
D. sns.plot_theme(name='whitegrid')

36 Which task most clearly demonstrates a typical advantage of Seaborn over basic Matplotlib commands?

Seaborn versus Matplotlib Medium
A. Setting exact tick positions and manually adjusting individual plot spines
B. Exporting a completed figure to a PNG file with a chosen resolution
C. Mapping a DataFrame category to color with hue and adding statistical estimates
D. Drawing a simple line from two Python lists on a single set of axes

37 A DataFrame df contains repeated sales observations for each region and quarter. Which call plots mean sales by quarter and uses separate colored lines for regions?

Data visualization using Seaborn Medium
A. sns.scatterplot(data=df, x='quarter', y='region', hue='sales')
B. sns.histplot(data=df, x='sales', y='quarter', hue='region')
C. sns.lineplot(data=df, x='region', y='quarter', size='sales')
D. sns.lineplot(data=df, x='quarter', y='sales', hue='region')

38 You have a correlation matrix stored in corr. Which Seaborn call best displays its values in a color-coded grid with numeric annotations?

Data visualization using Seaborn Medium
A. sns.pairplot(corr, annot=True, palette='coolwarm')
B. sns.heatmap(corr, annot=True, cmap='coolwarm')
C. sns.boxplot(corr, annot=True, color='coolwarm')
D. sns.histplot(corr, labels=True, cmap='coolwarm')

39 A researcher wants pairwise scatter plots for several numeric columns and distributions along the diagonal, separated by species color. Which call is most appropriate?

Data visualization using Seaborn Medium
A. sns.pairplot(data=df, hue='species')
B. sns.relplot(data=df, hue='species')
C. sns.catplot(data=df, hue='species')
D. sns.displot(data=df, hue='species')

40 A team needs a Python dashboard in which changing a dropdown automatically updates a graph through declared input-output relationships. Which tool and feature best match this requirement?

Introduction to data visualization tools for creating dashboards Medium
A. Matplotlib with static figure legends
B. Seaborn with figure-level themes
C. Plotly Dash with callback functions
D. Pandas with DataFrame styling

41 Consider: fig, (ax1, ax2) = plt.subplots(1, 2); plt.sca(ax1); ax2.plot([0, 1], [2, 3]); plt.xlim(0, 5). Assuming no other commands intervene, which axes receives the new x-limits?

Introduction to Matplotlib Hard
A. ax1 only
B. Neither axes, because calling the object-oriented ax2.plot method disables subsequent pyplot state changes
C. Both ax1 and ax2
D. ax2 only

42 What is rendered by plt.plot([0, 1, 2, 3], [0, 1, np.nan, 3], marker='o') under Matplotlib's standard handling of missing values?

Line plots Hard
A. One continuous line through all four coordinates
B. No line or markers because one missing value invalidates the complete data series
C. A segment from the first to second point, plus an isolated marker at the fourth point
D. A segment directly connecting the second and fourth points, with no marker at the missing point

43 What is the key consequence of running plt.bar(['A', 'B', 'A'], [4, 5, 7]) without manually assigning numeric positions?

Bar charts Hard
A. The second A replaces the first before any rectangular patches are constructed
B. Matplotlib automatically combines the two A heights into one bar
C. The two A bars receive the same categorical x-position and overlap
D. Matplotlib creates distinct positions labeled A, B, and A

44 Two scatter calls display subsets of one variable using the same colormap. How should the calls be configured so that a value of always maps to the same color, even when the subsets have different ranges?

Scatter plots Hard
A. Pass one shared Normalize object and the same colormap to both calls
B. Sort each subset by color value before calling scatter
C. Allow each scatter call to infer its own limits, then create one colorbar from the second collection
D. Pass identical alpha and edgecolors values to both calls

45 Assuming a Matplotlib version supporting normalize, what does plt.pie([0.2, 0.3], normalize=False, autopct='%1.0f%%') produce?

Pie charts Hard
A. An exception because pie-chart values must sum exactly to one whenever normalization is disabled
B. A half-circle pie labeled approximately 40% and 60%
C. A full-circle pie labeled approximately 40% and 60%
D. A half-circle pie labeled approximately 20% and 30%

46 In ax.boxplot(data, whis=(5, 95)), how are the whiskers determined?

Box-and-whisker plots Hard
A. They extend exactly five and ninety-five standard deviations from the mean
B. They use the 5th and 95th percentile limits, extending to qualifying observations
C. They use and as asymmetric fences
D. They remain at the usual limits, while only the displayed outlier symbols are filtered by percentile

47 For data [0.2, 0.8, 1.2, 2.2], bins [0, 1, 3], and density=True, what are the two histogram heights?

Histograms Hard
A. 0.25 and 0.25, because density divides every count only by the total number of observations
B. 0.5 and 0.5
C. 2.0 and 2.0
D. 0.5 and 0.25

48 What is the shape of axs returned by fig, axs = plt.subplots(2, 1, squeeze=False)?

Multiple subplots in one figure Hard
A. (1, 2)
B. (2,)
C. No shape, because axs is always a Python list when one dimension equals one
D. (2, 1)

49 A DataFrame contains several score rows for each category. What does sns.barplot(data=df, x='category', y='score') display by default in modern Seaborn?

Introduction to Seaborn Hard
A. The category mean with an estimated confidence interval
B. The category sum with an error bar equal to one population standard deviation
C. One separate bar for every row in the DataFrame
D. The category median with the full observed range

50 Which statement correctly distinguishes Seaborn figure-level and axes-level interfaces?

Seaborn versus Matplotlib Hard
A. displot is a direct Matplotlib function re-exported by Seaborn, whereas histplot performs DataFrame reshaping before calling it
B. histplot manages a FacetGrid, while displot must receive an ax argument
C. displot manages its own figure, while histplot can draw on a supplied Matplotlib axes
D. Both functions are axes-level and differ only in their default color palettes

51 For sns.histplot(data=df, x='value', hue='group', stat='density', common_norm=False), what is the intended normalization across hue groups?

Data visualization using Seaborn Hard
A. Every individual bin is normalized so its grouped heights sum to one
B. Each group's histogram is normalized independently to unit area
C. The largest group is assigned unit area, and every smaller group's area is scaled according to its sample-size ratio
D. All groups jointly have a combined histogram area of one

52 A dashboard must update several linked charts when a user selects a region. Which architecture most directly supports this requirement?

Introduction to data visualization tools for creating dashboards Hard
A. A separate database table for every possible selection, with no event-handling layer
B. A shared state or callback that filters data and updates dependent chart components
C. A collection of unrelated static PNG files generated once when the server starts
D. A Matplotlib script that calls plt.show() for each chart and relies on the operating system to synchronize user selections

53 Given x = [3, 1, 2] and y = [30, 10, 20], what path does plt.plot(x, y) draw?

Line plots Hard
A. It sorts by x and connects to to
B. It refuses to draw because line plots require monotonically increasing x-values unless a sorting keyword is enabled
C. It connects to to in input order
D. It sorts x but leaves y unchanged, connecting to to

54 To construct a correctly diverging stacked bar chart containing both positive and negative components, how should the bottom values generally be maintained?

Bar charts Hard
A. Sort components by absolute magnitude and use the previous bar's geometric center as the next baseline
B. Use separate cumulative baselines for positive and negative components
C. Set every component's baseline to zero and increase only its width
D. Use one cumulative baseline for all components regardless of sign

55 In Matplotlib, scatter(..., s=...) interprets s as marker area in points squared. Approximately how must s change to double a circular marker's diameter?

Scatter plots Hard
A. Add two points to s, because marker diameter rather than area is transformed by the display coordinate system
B. Multiply s by
C. Multiply s by
D. Multiply s by

56 Using the usual percentile calculation and whis=1.5, what does a box plot of [1, 2, 3, 4, 100] show?

Box-and-whisker plots Hard
A. Whiskers at the theoretical fences -1 and 7, even though neither fence is an observed data value
B. Whiskers at 2 and 4, with both 1 and 100 as fliers
C. Whiskers at 1 and 4, with 100 as a flier
D. Whiskers at 1 and 100, with no fliers

57 For a nonempty dataset with finite values, density=True, and cumulative=True, what should the final cumulative histogram height be, apart from floating-point error?

Histograms Hard
A. The total number of observations, because cumulative mode overrides density
B. The height of the final noncumulative bin, since cumulative mode changes only the appearance of the bars
C. The width of the final bin, because density normalization is applied after accumulation
D. 1, because the integrated density accumulates to total probability

58 In plt.subplots(2, 2, sharex='col'), which axes share x-axis properties?

Multiple subplots in one figure Hard
A. Axes in the same row
B. Axes in the same column
C. Only the two diagonal axes, because column sharing pairs axes by their flattened-array indices
D. All four axes

59 A long-form DataFrame has repeated measurements with columns subject, time, and value. Which call draws one trajectory per subject without aggregating subjects at each time?

Data visualization using Seaborn Hard
A. sns.lineplot(data=df, x='time', y='value', units='subject', estimator=None)
B. sns.lineplot(data=df, x='time', y='value', hue='subject', estimator='median', errorbar=('ci', 95))
C. sns.lineplot(data=df, x='subject', y='value', errorbar=None)
D. sns.lineplot(data=df, x='time', y='value', estimator='mean')

60 A dashboard receives millions of timestamped observations, but its chart is only 1200 pixels wide. Which strategy most effectively improves interactive latency while preserving the visible trend?

Introduction to data visualization tools for creating dashboards Hard
A. Render all records repeatedly on the server, encode each frame as an uncompressed image, and disable caching to guarantee fresh computation
B. Filter, aggregate, or downsample to the display resolution and cache reusable results
C. Convert every observation into an independent dashboard component
D. Send every raw observation to the browser and increase the line width