Data Science & ML

Visualization with Matplotlib & Seaborn

Figures, axes, subplots, line plots, scatter plots, histograms, heatmaps, styling, customization

20 interview questionsยท
Mid-Level
1

What is the main difference between the pyplot interface and the object-oriented interface in Matplotlib?

Answer

The pyplot interface (plt.plot, plt.title) is a MATLAB-style API that implicitly manages current figures and axes, convenient for quick simple plots. The object-oriented interface (fig, ax = plt.subplots()) gives explicit control over each element (Figure, Axes) and is recommended for complex plots, multiple subplots, or production scripts, as it makes code more readable and maintainable.

2

Which method should be used to create a figure with a grid of 2 rows and 3 columns of subplots?

Answer

The function plt.subplots(2, 3) creates a figure containing a grid of 2 rows and 3 columns of subplots. It returns a tuple (fig, axes) where axes is a 2D NumPy array of shape (2, 3) allowing access to each subplot via axes[row, col]. This approach is the most concise and idiomatic way to create regular grids of subplots in Matplotlib.

3

How to display a correlation heatmap of a Pandas DataFrame with Seaborn?

Answer

To display a correlation heatmap, first calculate the correlation matrix with df.corr(), then pass the result to sns.heatmap(). The option annot=True displays correlation values in each cell, making it easier to read. This combination is the standard pattern for visualizing correlations between numerical variables in exploratory data analysis.

4

What is the role of the 'bins' parameter in plt.hist()?

5

How to share the Y axis between multiple subplots in the same row?

+17 interview questions

Master Data Science & ML for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free