
Visualization with Matplotlib & Seaborn
Figures, axes, subplots, line plots, scatter plots, histograms, heatmaps, styling, customization
1What is the main difference between the pyplot interface and the object-oriented interface in Matplotlib?
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.
2Which method should be used to create a figure with a grid of 2 rows and 3 columns of subplots?
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.
3How to display a correlation heatmap of a Pandas DataFrame with Seaborn?
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.
What is the role of the 'bins' parameter in plt.hist()?
How to share the Y axis between multiple subplots in the same row?
+17 interview questions
Other Data Science & ML interview topics
Python Basics
Python Object-Oriented Programming
Python Data Structures
Git Fundamentals
SQL Basics
NumPy Fundamentals
Pandas Basics
Jupyter & Google Colab
SQL Joins & Advanced Queries
Advanced Pandas
Interactive Visualizations with Plotly
Descriptive Statistics
Inferential Statistics
Web Scraping
BigQuery & Cloud Data
Feature Engineering
Supervised ML: Regression
Supervised ML: Classification
Decision Trees & Ensembles
Unsupervised ML
ML Pipelines & Validation
Time Series & Forecasting
Deep Learning Fundamentals
TensorFlow & Keras
CNN & Image Classification
RNN & Sequences
Transformers & Attention
NLP & Hugging Face
GenAI & LangChain
MLOps & Deployment
Master Data Science & ML for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free