Plotting with Secondary Axes in Matplotlib
📖 Scenario: You are analyzing the sales and profit data of a small store. You want to visualize both sales and profit trends on the same plot but with different scales.
🎯 Goal: Create a line plot with sales on the primary y-axis and profit on a secondary y-axis using Matplotlib.
📋 What You'll Learn
Create a dictionary called
data with keys 'Month', 'Sales', and 'Profit' and the exact values provided.Create a variable called
months that holds the list of months from the data dictionary.Create a Matplotlib plot with sales data on the primary y-axis and profit data on a secondary y-axis.
Label both y-axes and the x-axis correctly.
Display the plot.
💡 Why This Matters
🌍 Real World
Visualizing two related but differently scaled data series on the same plot helps businesses understand relationships like sales and profit trends over time.
💼 Career
Data analysts and scientists often use secondary axes in reports and dashboards to present multiple metrics clearly and effectively.
Progress0 / 4 steps