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. Writing web pages
B. Creating data visualizations
C. Managing computer files
D. Installing Python packages

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

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

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

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

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

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

5 What is a bar chart commonly used to compare?

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

6 Which Matplotlib function creates a vertical bar chart?

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

7 What does a scatter plot display?

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

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

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

9 What does a pie chart show?

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

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

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

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

Box-and-whisker plots Easy
A. The names of categories
B. The distribution of data
C. The colors in an image
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 maximum only
B. The mean only
C. The median
D. The minimum only

13 What is a histogram mainly used to show?

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

14 What are the intervals in a histogram commonly called?

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

15 Why are multiple subplots used in one figure?

Multiple subplots in one figure Easy
A. To remove all chart labels
B. To display several plots together
C. To convert charts into tables
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 database management tool
B. A Python visualization library
C. A text editing application
D. A Python operating system

18 Which statement best describes Seaborn compared with Matplotlib?

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

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

Data visualization using Seaborn Easy
A. relationshipplot()
B. scatterplot()
C. dotplotter()
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 display important information in one view
C. To hide charts from users
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, ax = plt.subplots(); ax.plot(x, y); ax.set_title('Trend')
B. fig, ax = plt.subplots(); fig.plot(x, y); fig.set_title('Trend')
C. ax = plt.figure(); ax.plot(x, y); ax.title('Trend')
D. fig = plt.subplots(); fig.plot(x, y); plt.set_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.scatter() twice with one shared marker, then call ax.grid()
B. Call ax.hist() twice with equal bins, then call ax.legend()
C. Call ax.plot() twice with different labels, then call ax.legend()
D. Call ax.bar() twice at identical positions, 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 linearly interpolated
C. The line usually contains a gap at that observation
D. The missing value is automatically replaced by zero

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 - width and x - width/2
B. x and x + 2 * width
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.plot(categories, values)
C. plt.bar(categories, values)
D. plt.hist(categories, values)

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

Scatter plots Medium
A. s controls marker area and c controls marker color
B. s controls line style and c controls axis 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. Connect every point using a solid line style
C. Replace all coordinates with their overall averages
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. autopct='%1.1f%%'
B. labels='%1.1f%%'
C. format='%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 must be an incorrect value that should be deleted
B. It lies above the arithmetic mean plus one standard deviation
C. It lies beyond the largest value within
D. It lies above the median plus exactly data units

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 has a larger arithmetic mean
B. Group A has fewer possible outliers
C. Group A has a larger interquartile range
D. Group A contains more observations

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.arange(0, 5, 2))
C. plt.hist(data, bins=np.linspace(0, 5, 5))
D. plt.hist(data, bins=[0, 1, 2, 3, 4])

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 orientation='horizontal'
B. Set cumulative=True
C. Set stacked=True
D. Set density=True

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[1, 2]
B. axes[2, 2]
C. axes[2, 3]
D. axes[1, 3]

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(4, 1, sharex=True)
B. plt.subplots(4, 1, sharey=True)
C. plt.subplots(1, 4, squeeze=False)
D. plt.subplots(1, 4, constrained_layout=False)

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

Introduction to Seaborn Medium
A. sns.plot_theme(name='whitegrid')
B. sns.apply_style(theme='whitegrid')
C. sns.create_theme(style='whitegrid')
D. sns.set_theme(style='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.histplot(data=df, x='sales', y='quarter', hue='region')
B. sns.lineplot(data=df, x='quarter', y='sales', hue='region')
C. sns.lineplot(data=df, x='region', y='quarter', size='sales')
D. sns.scatterplot(data=df, x='quarter', y='region', hue='sales')

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.boxplot(corr, annot=True, color='coolwarm')
B. sns.pairplot(corr, annot=True, palette='coolwarm')
C. sns.histplot(corr, labels=True, cmap='coolwarm')
D. sns.heatmap(corr, annot=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.displot(data=df, hue='species')
B. sns.catplot(data=df, hue='species')
C. sns.pairplot(data=df, hue='species')
D. sns.relplot(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. Seaborn with figure-level themes
B. Matplotlib with static figure legends
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. Both ax1 and ax2
B. Neither axes, because calling the object-oriented ax2.plot method disables subsequent pyplot state changes
C. ax1 only
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. A segment from the first to second point, plus an isolated marker at the fourth point
C. No line or markers because one missing value invalidates the complete data series
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 identical alpha and edgecolors values to both calls
B. Sort each subset by color value before calling scatter
C. Pass one shared Normalize object and the same colormap to both calls
D. Allow each scatter call to infer its own limits, then create one colorbar from the second collection

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. A half-circle pie labeled approximately 20% and 30%
B. A half-circle pie labeled approximately 40% and 60%
C. An exception because pie-chart values must sum exactly to one whenever normalization is disabled
D. A full-circle pie labeled approximately 40% and 60%

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

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

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.5 and 0.25
B. 0.25 and 0.25, because density divides every count only by the total number of observations
C. 0.5 and 0.5
D. 2.0 and 2.0

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

Multiple subplots in one figure Hard
A. No shape, because axs is always a Python list when one dimension equals one
B. (2,)
C. (1, 2)
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 median with the full observed range
C. The category sum with an error bar equal to one population standard deviation
D. One separate bar for every row in the DataFrame

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

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

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. The largest group is assigned unit area, and every smaller group's area is scaled according to its sample-size ratio
B. Every individual bin is normalized so its grouped heights sum to one
C. All groups jointly have a combined histogram area of one
D. Each group's histogram is normalized independently to unit area

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

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

Line plots Hard
A. It connects to to in input order
B. It sorts by x and connects to to
C. It refuses to draw because line plots require monotonically increasing x-values unless a sorting keyword is enabled
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. Use one cumulative baseline for all components regardless of sign
B. Sort components by absolute magnitude and use the previous bar's geometric center as the next baseline
C. Use separate cumulative baselines for positive and negative components
D. Set every component's baseline to zero and increase only its width

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. Multiply s by
B. Add two points to s, because marker diameter rather than area is transformed by the display coordinate system
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 1 and 4, with 100 as a flier
B. Whiskers at 1 and 100, with no fliers
C. Whiskers at 2 and 4, with both 1 and 100 as fliers
D. Whiskers at the theoretical fences -1 and 7, even though neither fence is an observed data value

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 width of the final bin, because density normalization is applied after accumulation
B. 1, because the integrated density accumulates to total probability
C. The height of the final noncumulative bin, since cumulative mode changes only the appearance of the bars
D. The total number of observations, because cumulative mode overrides density

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 column
B. All four axes
C. Axes in the same row
D. Only the two diagonal axes, because column sharing pairs axes by their flattened-array indices

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', estimator='mean')
B. sns.lineplot(data=df, x='subject', y='value', errorbar=None)
C. sns.lineplot(data=df, x='time', y='value', units='subject', estimator=None)
D. sns.lineplot(data=df, x='time', y='value', hue='subject', estimator='median', errorbar=('ci', 95))

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. Convert every observation into an independent dashboard component
C. Send every raw observation to the browser and increase the line width
D. Filter, aggregate, or downsample to the display resolution and cache reusable results