0
0
Matplotlibdata~30 mins

Seaborn figure-level vs axes-level in Matplotlib - Hands-On Comparison

Choose your learning style9 modes available
Seaborn Figure-level vs Axes-level Plotting
📖 Scenario: You are analyzing a small dataset of daily temperatures and humidity levels. You want to visualize the data using Seaborn plots. Seaborn offers two types of plotting functions: figure-level and axes-level. Figure-level functions create their own figure and manage the layout, while axes-level functions draw on an existing matplotlib axes.Understanding the difference helps you control how your plots appear and combine multiple plots in one figure.
🎯 Goal: Build two simple plots using Seaborn: one figure-level plot and one axes-level plot. Learn how to create the data, configure a helper variable, apply the correct plotting function, and display the result.
📋 What You'll Learn
Create a pandas DataFrame with exact data for temperature and humidity
Create a matplotlib figure and axes for the axes-level plot
Use a Seaborn figure-level function to plot temperature distribution
Use a Seaborn axes-level function to plot humidity on the created axes
Display both plots correctly
💡 Why This Matters
🌍 Real World
Data scientists often need to visualize data clearly. Knowing when to use figure-level or axes-level functions helps create flexible and well-organized plots.
💼 Career
Understanding Seaborn's plotting levels is important for data analysts and scientists to produce clear reports and dashboards.
Progress0 / 4 steps
1
Create the DataFrame with temperature and humidity
Create a pandas DataFrame called weather_data with two columns: 'temperature' and 'humidity'. Use these exact values: temperature = [22, 25, 19, 23, 21], humidity = [30, 45, 50, 40, 35].
Matplotlib
Need a hint?

Use pd.DataFrame with a dictionary containing the two lists for temperature and humidity.

2
Create a matplotlib figure and axes for the axes-level plot
Import matplotlib.pyplot as plt. Create a figure and axes using plt.subplots() and assign them to variables fig and ax.
Matplotlib
Need a hint?

Use plt.subplots() to get both figure and axes objects.

3
Plot temperature with a Seaborn figure-level function and humidity with an axes-level function
Import seaborn as sns. Use the figure-level function sns.histplot to plot the 'temperature' column from weather_data. Then use the axes-level function sns.scatterplot to plot 'humidity' on the ax axes. Use weather_data.index for the x-axis and weather_data['humidity'] for the y-axis.
Matplotlib
Need a hint?

Figure-level functions like sns.histplot create their own figure. Axes-level functions like sns.scatterplot need the ax parameter to draw on the existing axes.

4
Display the plots
Use plt.show() to display the plots.
Matplotlib
Need a hint?

Call plt.show() to display all open figures.