"""Render all states from state_comparison.csv; matplotlib 3.10.7.""" import csv from pathlib import Path import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from matplotlib.lines import Line2D from matplotlib.ticker import FuncFormatter def render(data_file, destination): with open(data_file, newline='', encoding='utf-8') as handle: rows=[r for r in csv.DictReader(handle) if r['geography_type']=='state'] rows.sort(key=lambda r: (-float(r['pce_per_person_usd']),r['area_name'])) assert len(rows)==51 destination=Path(destination);destination.mkdir(parents=True,exist_ok=True) plt.rcParams.update({'font.family':'DejaVu Sans','font.size':11,'text.color':'#26352e', 'axes.labelcolor':'#26352e','xtick.color':'#526358','ytick.color':'#26352e', 'svg.fonttype':'none','svg.hashsalt':'acd-state-spending-v1', 'figure.facecolor':'#f7f8f0','axes.facecolor':'#f7f8f0'}) for mobile in (False,True): fig,ax=plt.subplots(figsize=(4.2,28) if mobile else (10,18)) fig.subplots_adjust(left=.47 if mobile else .25,right=.96,top=.90,bottom=.11) fig.text(.04,.98,'State spending:\nbefore and after local\nprice adjustment' if mobile else 'State spending, before and after\nadjusting for local prices',fontsize=16 if mobile else 21,weight='bold',va='top') fig.text(.04,.947 if mobile else .945,('2024 annual PCE per resident\n50 states and DC · Ordered by current dollars\nBoth dots show the same year.' if mobile else '2024 annual PCE per resident · 50 states and DC\nOrdered by current-dollar spending; both dots use the same year.'),fontsize=11 if mobile else 12,va='top',linespacing=1.5) fig.legend([Line2D([0],[0],marker='o',color='#af743c',linestyle=''),Line2D([0],[0],marker='D',color='#315b49',linestyle='')],['Current dollars','At national prices'],loc='upper left',bbox_to_anchor=(.035,.925),frameon=False,ncol=2,fontsize=10 if mobile else 12) for i,row in enumerate(rows): nominal=float(row['pce_per_person_usd']);adjusted=float(row['pce_at_national_prices_usd']) ax.plot([nominal,adjusted],[i,i],color='#a9b7a9',lw=1.6,zorder=1) ax.scatter(nominal,i,color='#af743c',s=29,zorder=3) ax.scatter(adjusted,i,color='#315b49',s=28,marker='D',zorder=3) ax.set_yticks(range(len(rows)),[r['area_name'] for r in rows]);ax.set_ylim(50.8,-.8) ax.set_xlim(35000,100000);ax.set_xticks([40000,60000,80000,100000] if mobile else range(40000,100001,10000)) ax.xaxis.set_major_formatter(FuncFormatter(lambda value,_:f'${value/1000:.0f}k')) ax.tick_params(axis='y',length=0,labelsize=12) ax.grid(axis='x',alpha=.18);ax.spines[['left','top','right']].set_visible(False) ax.spines['bottom'].set_color('#b5c0b5');ax.set_xlabel('Annual spending per resident',labelpad=12) footer=('Adjustment: current dollars ÷ (all-items RPP / 100).\nIncludes imputed and third-party spending; not a household budget.\nPCE: September 2026 edition. RPP: February 2026 edition.\nSources: BEA; Actually Clean Data calculations.') if mobile:footer='Current dollars ÷ (all-items RPP / 100).\nIncludes imputed and third-party spending.\nNot a household budget.\nPCE: September 2026 edition.\nRPP: February 2026 edition.\nSources: BEA; Actually Clean Data calculations.' fig.text(.04,.014,footer,fontsize=11,linespacing=1.5) name='state-spending'+('-mobile' if mobile else '') fig.savefig(destination/(name+'.svg'),metadata={'Date':None,'Creator':'Actually Clean Data; matplotlib 3.10.7'}) if not mobile:fig.savefig(destination/(name+'.png'),dpi=160) plt.close(fig) if __name__=='__main__': render('state_comparison.csv','figures')