Quiz: Plotly Express
Answer all 20 questions. Answers and explanations are hidden below each question.
Part I: Multiple Choice (10 questions)
Q1. Which of the following is Plotly's top-level chart container?
A) Canvas B) Figure C) Axes D) Layout
Answer
**B.** A Plotly Figure contains a list of traces (data) and a layout. It is the root object that gets serialized to JSON for rendering.Q2. What is a "trace" in Plotly?
A) The log of a function call B) One layer of the chart, such as a line or set of bars C) A user interaction event D) The animation sequence
Answer
**B.** A trace is one visual layer (a scatter, a line, a bar series, a heatmap). A figure can have many traces; each is independent but shares the axes.Q3. Which parameter of px.scatter maps a categorical variable to marker color?
A) c
B) color
C) hue
D) palette
Answer
**B.** Plotly Express uses `color`. (Seaborn uses `hue`, matplotlib uses `c`.) The naming difference is a mild inconvenience when switching between libraries.Q4. What does animation_group do in px.scatter(..., animation_frame="year")?
A) Groups multiple charts into one figure B) Keeps the same entity (e.g., country) as a single animated object across frames C) Sets the color palette for the animation D) Controls the playback speed
Answer
**B.** `animation_group` tells Plotly to match points across frames so the same entity moves smoothly. Without it, each frame is treated as independent points, which looks like a slideshow rather than motion.Q5. Which library does Plotly use for static image export (PNG, SVG, PDF)?
A) orca (deprecated) B) kaleido C) matplotlib D) imageio
Answer
**B.** kaleido is the modern static export engine for Plotly. Orca was the older tool and has been deprecated. Install with `pip install kaleido` and use `pio.write_image`.Q6. Adding a range slider to a time-series chart requires:
A) fig.add_trace(go.RangeSlider())
B) fig.update_layout(xaxis_rangeslider_visible=True)
C) px.slider(...)
D) A separate JavaScript file
Answer
**B.** Range sliders are a layout property. Set `xaxis_rangeslider_visible=True` and Plotly adds the slider below the chart automatically.Q7. Plotly's rendering architecture is best described as:
A) Pure Python — the charts are drawn by matplotlib under the hood B) Pure JavaScript — there is no Python involvement C) Python describes a JSON spec; JavaScript (plotly.js) renders it in the browser D) Python and JavaScript share rendering duties
Answer
**C.** Python builds a data structure (a Figure object, serializable to JSON), and plotly.js running in the browser interprets the JSON and draws the chart. This split is why Plotly output is large (the JS must be loaded) and why the charts are interactive by default (JS can respond to events).Q8. Which Plotly Express chart type is most similar to seaborn's pairplot?
A) px.scatter
B) px.scatter_matrix
C) px.parallel_coordinates
D) px.density_heatmap
Answer
**B.** `px.scatter_matrix` produces a grid of pairwise scatter plots for the specified dimensions — the direct analog of seaborn's pairplot. `px.parallel_coordinates` is a different multi-variable chart type.Q9. The Plotly Express trendline parameter supports which of the following?
A) Only OLS linear regression B) OLS, LOWESS, rolling average, expanding mean, and EWM C) Any scikit-learn estimator D) Custom functions
Answer
**B.** `trendline` accepts `"ols"`, `"lowess"`, `"rolling"`, `"expanding"`, and `"ewm"`. The underlying fit is done by statsmodels for OLS/LOWESS and by pandas for the smoothing options.Q10. When should you prefer matplotlib over Plotly Express for producing a chart?
A) When the output will be viewed on a screen B) When the chart must be printed or included in a LaTeX document C) When you want a trendline D) When the dataset is small
Answer
**B.** For print output, matplotlib produces higher-quality static images with better typographic control and smaller file sizes. Plotly's strength is screen interactivity, which is irrelevant in print contexts.Part II: Short Answer (10 questions)
Q11. Explain the difference between Plotly Express and Plotly Graph Objects, and when you would use each.
Answer
Plotly Express (`px`) is a high-level wrapper that produces common chart types in one call. Graph Objects (`go`) is the lower-level API where you manually construct traces and layouts. Use Plotly Express for standard charts (faster to write, consistent API); drop to Graph Objects when you need mixed trace types, interactive buttons/dropdowns, custom subplot layouts, or property-level fine control.Q12. What are three ways to customize hover information in Plotly Express, from simplest to most flexible?
Answer
(1) `hover_name` (prominent title) and `hover_data` (dict of columns and format strings). (2) Custom `hovertemplate` string with substitutions like `%{x}`, `%{y}`, and `%{customdata[N]}`. (3) Disabling hover with `hoverinfo='skip'` on specific traces.Q13. Why should you always set range_x and range_y explicitly when using animation_frame?
Answer
Without explicit ranges, Plotly auto-scales the axes per frame. The axes then shift during animation, which is disorienting — the viewer sees data "moving" when in fact the scale is moving under the data. Fixing the ranges keeps the axes stable and lets the animation communicate actual data change.Q14. What are three options for the include_plotlyjs parameter of pio.write_html, and what are the trade-offs?
Answer
(1) `True` — embeds the full plotly.js library (~3 MB). File works offline but is large. (2) `"cdn"` — references plotly.js from a CDN. File is small but requires internet. (3) `False` — omits the library entirely. Smallest file but the library must be loaded externally.Q15. Name four built-in Plotly templates and describe when you might use one of them.
Answer
`"plotly"` (default, with gridlines), `"plotly_white"` (clean white background), `"plotly_dark"` (dark mode), `"simple_white"` (minimal chrome for publication), `"presentation"` (larger text for slides), `"ggplot2"` and `"seaborn"` (mimicking those libraries' defaults). Use `"simple_white"` for clean publication-style output; `"plotly_dark"` for dashboards with dark mode; `"presentation"` for slide decks.Q16. Explain how Plotly's architecture (Python describes, JavaScript renders) affects file size and interactivity.
Answer
The architecture requires the JavaScript library to be available when the chart renders, which inflates file size (the library is several megabytes) unless you use CDN mode. In exchange, interactivity comes for free — hover, zoom, pan, and click are implemented in JavaScript and do not require any Python-side logic. Matplotlib has the opposite trade-off: small static files but no interactivity by default.Q17. Describe what facet_col_wrap does and when to use it.
Answer
`facet_col_wrap=N` makes a single-dimension facet wrap into multiple rows of N columns. Without it, all facets appear in a single row, which becomes unreadable when there are more than about four categories. Use `facet_col_wrap` to control the grid shape, e.g., `facet_col_wrap=4` for 12 categories in a 3×4 grid.Q18. A Plotly scatter chart with 500,000 points is sluggish. What trace-type change would help, and why?
Answer
Switch from `scatter` (SVG-rendered) to `scattergl` (WebGL-rendered). SVG creates one DOM element per point, which is slow for tens of thousands of elements. WebGL renders via the GPU and handles millions of points smoothly. Plotly Express has a `render_mode="webgl"` parameter on some chart types (e.g., `px.scatter(..., render_mode="webgl")`) that triggers the switch automatically.Q19. What does the chapter mean by "the interactive mindset"? How is it different from the static-chart mindset?
Answer
Static-chart design: anticipate all the questions readers will ask and answer them on the page. Interactive-chart design: define the question space — the set of questions the reader can ask — and build affordances (hover, zoom, filter) that let them explore. You stop designing the answer and start designing the ability to ask questions. This shifts the chart from a frozen conclusion to a living exploration tool.Q20. Why does the chapter's threshold concept ("interactive is not a gimmick") connect to Shneiderman's mantra from Chapter 9?
Answer
Shneiderman's mantra — overview first, zoom and filter, details on demand — describes the general workflow for exploring information. Interactive charts implement all three levels in a single figure: the overview is the default view, zoom/filter is the range slider or interactive legend, and details on demand is the hover tooltip. A well-designed interactive chart thus replaces the entire static dashboard that Shneiderman's mantra would otherwise require. That is why interactivity is foundational rather than decorative.Scoring Rubric
| Score | Level | Meaning |
|---|---|---|
| 18–20 | Mastery | You can design and customize interactive Plotly Express charts confidently, and you understand when to use Plotly vs. matplotlib/seaborn. |
| 14–17 | Proficient | You know the main chart types and parameters; review hover customization and the architecture section. |
| 10–13 | Developing | You grasp the big picture; re-read Sections 20.4-20.8 and work all Part B exercises. |
| < 10 | Review | Re-read the full chapter and complete all Part A and Part B exercises before moving on to Chapter 21. |
After this quiz, move on to Chapter 21 (Plotly Graph Objects), which introduces the lower-level API for building custom interactive figures.