Explain the grammar of graphics and how Matplotlib and Seaborn compare to ggplot2 and plotnine
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Other
Explain the grammar-of-graphics mental model (data, geometric mark, aesthetic mapping, scale, facet) and how Matplotlib and Seaborn compare to `ggplot2`/`plotnine`.
```hint Who owns each part
Take one concrete chart, such as a scatter plot colored by group and split into panels by region. For each part of the grammar, ask whether the library handles it for you or you write it yourself.
```
### What a Strong Answer Covers
- Each component of the grammar and what it is responsible for, ideally shown on one example plot.
- How ggplot2 and plotnine express the grammar, and what "declarative" means in practice.
- Where Seaborn fits, covering both its figure-level functions and its objects interface.
- What Matplotlib leaves to the user, what it gives in return, and which libraries actually render through it.
- When you would reach for each tool.
### Follow-up Questions
- Which parts of the full grammar (statistical transformations, coordinate systems, themes) does the five-part list leave out, and where do they appear in these libraries?
- Why does the grammar expect tidy, long-format data, and how would you reshape a wide table for it?
- In plain Matplotlib, how do you keep a group's color consistent across facets?
- How do you fine-tune a Seaborn figure-level plot after the grammar has done the layout?
Overview: Asks for the grammar-of-graphics model of a chart (data, marks, aesthetic mappings, scales, facets) and a comparison of Matplotlib and Seaborn with ggplot2 and plotnine. Tests whether a candidate understands declarative versus imperative plotting and when to use each Python library.