Using the Fig, ax = plt.subplots Pattern in Matplotlib
📖 Scenario: You are a data analyst who wants to create a simple line chart to show sales over a week. You will use the fig, ax = plt.subplots() pattern to create the plot.
🎯 Goal: Build a line plot using fig, ax = plt.subplots() to display sales data for 7 days.
📋 What You'll Learn
Create a list called
days with the values: 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'.Create a list called
sales with the values: 150, 200, 170, 220, 180, 190, 210.Use
fig, ax = plt.subplots() to create the figure and axes.Plot the sales data on the axes with days on the x-axis and sales on the y-axis.
Set the title of the plot to 'Weekly Sales'.
Display the plot using
plt.show().💡 Why This Matters
🌍 Real World
Creating clear and simple charts is important for sharing data insights with others in business, science, and everyday life.
💼 Career
Data analysts and scientists use matplotlib and the fig, ax = plt.subplots() pattern to build flexible and professional plots for reports and presentations.
Progress0 / 4 steps