Last active
May 15, 2025 19:09
-
-
Save cavedave/1083d866f78760b036263a98cb68c1dc to your computer and use it in GitHub Desktop.
ukincome.ipynb
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import matplotlib.pyplot as plt
Create the figure
plt.figure(figsize=(12, 7))
Plot main income line and the trend
plt.plot(data["Year"], data["Work_Mean"], linestyle='-', marker='o', color='red', linewidth=2)#label="Working Households",
plt.plot(data["Year"], data["Trend_Work"], linestyle='--', color='black', linewidth=2)#label="1977–2007 Trend (3% CAGR)",
Shaded Recessions and Crises
Add shaded regions for recessions
Add precise recession markers at the bottom
plt.fill_betweenx([0, 100000], 1980 + 0/4, 1981 + 1/4, color='gray', alpha=0.5, linewidth=0) # 1980 Q1 to 1981 Q1
plt.text(1981.4, 1000, "Recession", fontsize=10, color="gray", va="center") # Label for 1980-1981 recession
plt.fill_betweenx([0, 100000], 1990 + 2/4, 1991 + 3/4, color='gray', alpha=0.5, linewidth=0) # 1990 Q3 to 1991 Q3
plt.text(1991.8, 1000, "Recession", fontsize=10, color="gray", va="center") # Label for 1990-1991 recession
plt.fill_betweenx([0, 100000], 2008 + 1/4, 2009 + 2/4, color='purple', alpha=0.5, linewidth=0) # 2008 Q2 to 2009 Q2
plt.text(2009.6, 1000, "Financial Crisis", fontsize=10, color="purple", va="center") # Label for 2008-2009 recession
plt.fill_betweenx([0, 100000], 2020 + 0/4, 2020 + 1/4, color='green', alpha=0.5, linewidth=0) # 2020 Q1 to 2020 Q2
plt.text(2020.5, 1000, "COVID", fontsize=10, color="green", va="center") # Label for 2020 recession
#plt.fill_betweenx([5000, 10000], 2016 + 2/4, 2021, color='gray', alpha=0.5, linewidth=0) # 2020 Q1 to 2020 Q2
#plt.text(2020.5, 5000, "Brexit: vote to exit", fontsize=10, color="gray", va="center") # Label for 2020 recession
plt.fill_betweenx([0, 100000], 2016.5, 2021.0, color='orange', alpha=0.25, linewidth=0)
plt.text(2018.5, 15000, "Brexit Transition", fontsize=10, color="darkorange", rotation=90, ha="center")
Titles and labels
plt.suptitle("Real Disposable Income of UK Working Households (1977–2023)", fontsize=19, y=0.98)
plt.title("Inflation-adjusted to 2022/23 prices. Data: ONS. Dashed line shows 1977–2007 growth continued.", fontsize=11, y=1.01)
plt.xlabel("Year", fontsize=12)
plt.ylabel("Mean Household Disposable Income (£)", fontsize=12)
Ticks and grid
plt.xticks(fontsize=10)
plt.yticks(fontsize=10)
plt.grid(True, which='major', linestyle='--', alpha=0.5)
Get the 2023 actual and trend values
actual_2023 = data.loc[data["Year"] == 2023, "Work_Mean"].values[0]
trend_2023 = data.loc[data["Year"] == 2023, "Trend_Work"].values[0]
#gap
Compute gap
gap = int(trend_2023 - actual_2023)
gap_midpoint = (actual_2023 + trend_2023) / 2
Add only the box, no line
plt.text(2021.6, (actual_2023 + trend_2023) / 2,
"£30,000+ gap",
fontsize=11, fontweight='bold',
va='center', ha='left',
bbox=dict(facecolor='white', edgecolor='gray', boxstyle='round,pad=0.2'))
Legend
#plt.legend(fontsize=11, loc="upper left")
plt.ylim(bottom=0000, top=85000)
Save and show
plt.savefig("final_income_graph.png", dpi=300, bbox_inches="tight")
plt.show()