Chapter 15 Quiz: Advanced Charts and Dashboards

Instructions: Select the best answer for each question. The answer key with explanations follows question 20.


Question 1

Which statement best describes the relationship between seaborn and matplotlib?

A) seaborn replaces matplotlib entirely and uses its own rendering engine B) seaborn is built on top of matplotlib — every seaborn plot is a matplotlib figure under the hood C) seaborn and matplotlib share a codebase but cannot be used in the same script D) seaborn uses matplotlib only for saving files, not for rendering


Question 2

You call sns.set_theme(style="whitegrid") at the top of your script. What does this do?

A) Applies the whitegrid style only to the next chart drawn B) Sets the default style for all subsequent seaborn plots in the session C) Creates a white grid background only for bar charts D) Overrides any plt.style.use() calls made after it


Question 3

You have a DataFrame with a single observation per group (one revenue total per region, no repeated measurements). You call sns.barplot(data=df, x="region", y="revenue"). What should you add to prevent potentially misleading confidence interval bars?

A) ci=None B) std=False C) errorbar=None D) Both A and C are correct depending on the seaborn version


Question 4

In sns.heatmap, what does annot=True do?

A) Adds a color bar (colorbar/legend) to the right of the heatmap B) Writes the numeric value of each cell inside the cell C) Annotates outlier cells with an asterisk D) Adds axis labels automatically from the DataFrame index


Question 5

Which seaborn plot type displays the median, interquartile range, and outliers of a distribution simultaneously?

A) sns.barplot B) sns.violinplot C) sns.boxplot D) sns.histplot


Question 6

You want to use a color palette that shows deviation from a midpoint — green for above-target and red for below-target. Which seaborn palette type is most appropriate?

A) Sequential palette (e.g., "Blues") B) Categorical palette (e.g., "muted") C) Diverging palette (e.g., "RdYlGn") D) Perceptual palette (e.g., "viridis")


Question 7

sns.pairplot is described in the chapter as "best for internal exploration, not for sharing with executives." What is the primary reason?

A) pairplot cannot be saved as a PNG B) pairplot requires more than 10 variables to produce meaningful output C) The output is dense and requires explanation; it is not self-explanatory to non-analysts D) pairplot only works with continuous variables, not categorical data


Question 8

What is the key practical advantage of plotly over seaborn for business stakeholder communication?

A) plotly charts load faster in Jupyter notebooks B) plotly charts are interactive HTML that can be hovered, zoomed, and filtered in any browser C) plotly uses less memory than seaborn for large datasets D) plotly supports more chart types than seaborn


Question 9

You call fig.write_html("dashboard.html", include_plotlyjs="cdn") instead of include_plotlyjs=True. What is the tradeoff?

A) The CDN version is slower to render; the embedded version renders instantly B) The CDN version produces a much smaller file but requires an internet connection to display C) The CDN version only works on Windows; the embedded version is cross-platform D) The CDN version cannot be emailed; the embedded version can


Question 10

In a plotly hover template, what does <extra></extra> do?

A) Adds a footer with extra data fields to the tooltip B) Suppresses the trace name box that plotly adds by default at the bottom of tooltips C) Extends the tooltip to show data from neighboring data points D) Adds the chart title to each hover tooltip


Question 11

You are building a plotly chart with two data series (Revenue and Gross Margin %) on the same x-axis. You want hovering over any x position to show both values simultaneously. Which layout setting achieves this?

A) fig.update_layout(hovermode="x unified") B) fig.update_layout(hovermode="combined") C) fig.update_traces(hoverlabel_namelength=-1) D) fig.update_layout(hover_sync=True)


Question 12

Which plotly chart type is specifically designed for hierarchical data with multiple levels and displays the hierarchy as nested rectangles where area represents magnitude?

A) px.sunburst B) px.treemap C) px.waterfall D) px.icicle


Question 13

You use make_subplots to create a 2×2 dashboard grid. The bottom-right panel will be a pie chart. What must you include in the specs argument to prevent a layout error?

A) specs=[[..., ...], [..., {"colspan": 2}]] B) specs=[[..., ...], [..., {"type": "pie"}]] C) specs=[[..., ...], [..., {"secondary_y": True}]] D) No special spec is needed; pie charts work in any subplot cell


Question 14

You want to add a reference line to a plotly scatter plot (e.g., a line representing a $175/hr rate). You do not want this line to show a hover tooltip. Which approach is correct?

A) Use fig.add_hline(y=175) with annotation_text="Standard Rate" B) Use fig.add_trace(go.Scatter(..., hoverinfo="skip")) with the line coordinates C) Use fig.add_shape(type="line", ...) (shapes don't have hover tooltips) D) Both B and C are valid approaches


Question 15

Which command saves a plotly figure as a high-quality static PNG (not HTML)?

A) fig.to_image("chart.png") B) fig.export_png("chart.png") C) fig.write_image("chart.png", width=1200, height=600, scale=2) D) plt.savefig("chart.png", dpi=150)


Question 16

In a go.Bar trace, you set textposition="outside". What does this do?

A) Places labels in the white space outside the chart frame B) Places the bar's value label above the bar (outside it) C) Moves the axis tick labels outside the plot area D) Places the bar's label to the right of the bar


Question 17

You build a plotly line chart using go.Scatter with two traces (actual and target). You want the target line to appear dashed. Which argument achieves this?

A) line={"style": "dashed"} B) line={"dash": "dash"} C) linestyle="--" (as in matplotlib) D) marker={"symbol": "line-ew"}


Question 18

Which statement about px.scatter with trendline="ols" is accurate?

A) It adds a manual trend line that you must compute with numpy before passing to plotly B) It uses ordinary least squares regression, requires statsmodels installed, and adds a regression line per color group automatically C) It draws the trend line but does not display regression statistics on hover D) It only works when the data has fewer than 100 points


Question 19

According to the chapter's decision guide, when should you use matplotlib instead of seaborn or plotly?

A) When your dataset has more than 1 million rows B) When you need pixel-precise control over every visual element, particularly for print or custom publication layouts C) When you are building interactive dashboards for web delivery D) When you are doing initial exploratory analysis and need confidence intervals


Question 20

Sandra Chen asks Priya for a dashboard she can open from her email, hover over data points, and share with the regional VPs (who also don't have Python). What is the correct delivery format?

A) A Jupyter notebook (.ipynb) saved to a shared drive B) A matplotlib figure saved as a PDF C) A plotly figure saved as a self-contained HTML file (include_plotlyjs=True) D) A seaborn figure saved as a high-resolution PNG


Answer Key

Q Answer Explanation
1 B seaborn is explicitly built on matplotlib. You can call plt functions after any seaborn call to further customize the chart.
2 B sns.set_theme() sets global session defaults for all subsequent seaborn plots until changed again.
3 D Both ci=None (seaborn < 0.12) and errorbar=None (seaborn 0.12+) suppress confidence intervals. The correct option depends on the installed version. Professional code should use errorbar=None for modern seaborn.
4 B annot=True writes each cell's numeric value inside the cell. You control formatting with fmt (e.g., fmt=".0f" for integers).
5 C sns.boxplot shows the median (center line), IQR (box), full range (whiskers), and outliers (individual dots). sns.violinplot shows distribution shape but not outliers as clearly.
6 C Diverging palettes like "RdYlGn" or "coolwarm" map a meaningful midpoint (zero, target, average) to a neutral color with two distinct hues for positive and negative deviation.
7 C pairplot produces a grid of scatter plots that requires understanding of what each pair represents. It rewards data-literate viewers. For executives, use focused single charts that tell one clear story.
8 B plotly's defining business advantage is interactive HTML output. Stakeholders can hover, zoom, filter, and explore without any Python installation.
9 B include_plotlyjs="cdn" reduces file size from ~3 MB to a few KB by linking to an external JavaScript file. The tradeoff is that the chart requires internet access to render.
10 B <extra></extra> is plotly's way of suppressing the default trace name label that appears as a colored rectangle at the bottom of each hover tooltip. Remove it for cleaner tooltips.
11 A hovermode="x unified" shows all series' values at a given x position in a single tooltip, aligned on a shared x. This is ideal for trend comparisons.
12 B px.treemap uses nested rectangles where area = magnitude. px.sunburst uses nested rings, which is slightly harder to compare by area. Both handle hierarchy.
13 B plotly's subplot system allocates x/y axes for each cell by default. Pie charts do not use standard x/y axes. Setting {"type": "pie"} in specs tells plotly to allocate that cell differently.
14 D Both approaches work. fig.add_shape(type="line", ...) draws a shape layer without any hover. fig.add_trace(go.Scatter(..., hoverinfo="skip")) adds a trace whose hover is suppressed. add_shape is cleaner for pure visual references.
15 C fig.write_image() saves static images. It requires the kaleido package installed separately. plt.savefig() is matplotlib's method and does not apply to plotly figures.
16 B textposition="outside" in a Bar trace places the text value above the bar (for vertical bars) or to the right (for horizontal bars).
17 B In plotly graph objects, line style is set via the line dictionary with the "dash" key. Valid values include "solid", "dash", "dot", "dashdot". Note: this is different from matplotlib's linestyle="--" syntax.
18 B trendline="ols" triggers plotly's built-in integration with statsmodels to compute and draw an ordinary least squares regression line per color group. Hovering over the trend line does show slope and intercept information.
19 B matplotlib offers the highest customization ceiling, making it ideal for precise print layouts, custom annotations, and publication-quality figures where every element must be placed exactly.
20 C A self-contained plotly HTML file (include_plotlyjs=True) is the correct choice. It requires no Python, no installation, and works in any modern browser. Jupyter notebooks require a Jupyter server; PDFs and PNGs are static and cannot be hovered.

Score guide: 18-20 correct = Mastery | 14-17 = Proficient | 10-13 = Review sections 15.3-15.7 | Below 10 = Re-read the full chapter