Broken axes concept
📖 Scenario: Imagine you are analyzing sales data for a store. The sales numbers vary a lot: some days have very low sales, and some days have very high sales. You want to create a chart that shows both low and high sales clearly without wasting space.
🎯 Goal: You will create a plot with broken axes using matplotlib to show sales data with a gap in the y-axis. This helps to focus on both small and large sales values in one chart.
📋 What You'll Learn
Create a list called
days with values from 1 to 10.Create a list called
sales with these exact values: 5, 7, 6, 100, 110, 105, 8, 6, 7, 5.Create a figure with two subplots stacked vertically sharing the x-axis.
Set the y-axis limits of the top subplot to show high sales (90 to 120).
Set the y-axis limits of the bottom subplot to show low sales (0 to 10).
Plot the sales data on both subplots using
ax.plot(days, sales).Hide the spines between the two subplots to show the break clearly.
Add diagonal lines to indicate the break in the y-axis.
Print the figure to display the broken axes plot.
💡 Why This Matters
🌍 Real World
Broken axes plots are useful when data has large gaps or outliers, such as sales data with occasional spikes, to show details clearly without wasting space.
💼 Career
Data scientists and analysts often use broken axes plots to communicate insights effectively when data ranges vary widely.
Progress0 / 4 steps