"""Export ranked cumulative CPI changes. Requires matplotlib; inputs are public results.""" import csv, textwrap from pathlib import Path import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from matplotlib.ticker import PercentFormatter def render(data_file='category_changes.csv', destination='figures'): with open(data_file, newline='') as f: rows=list(csv.DictReader(f)) destination=Path(destination); destination.mkdir(parents=True, exist_ok=True) benchmark=next(r for r in rows if r['item_code']=='SA0') broad=sorted([r for r in rows if r['broad_group']=='yes']+[benchmark],key=lambda r:-float(r['change_pct'])) detailed=rows[:10]+list(reversed(rows[-5:])) plt.rcParams.update({'font.family':'DejaVu Sans','font.size':12,'text.color':'#21332b','axes.labelcolor':'#21332b','xtick.color':'#4b5d53','ytick.color':'#21332b','svg.fonttype':'none','svg.hashsalt':'acd-cpi-decade-v1','figure.facecolor':'#f7f8f0','axes.facecolor':'#f7f8f0'}) for kind,selected in [('broad-groups',broad),('largest-changes',detailed)]: for mobile in (False,True): detailed_view=kind=='largest-changes' fig,ax=plt.subplots(figsize=((5.2,16 if detailed_view else 8.5) if mobile else (11,11 if detailed_view else 7.5))) fig.subplots_adjust(left=.48 if mobile else .39,right=.88,top=.83 if mobile else .84,bottom=(.17 if detailed_view else .24) if mobile else .19) title='Ten years of consumer price changes' if not detailed_view else 'Largest increases and declines' fig.text(.035,.97,textwrap.fill(title,29) if mobile else title,fontsize=19 if mobile else 25,weight='bold',va='top') fig.text(.035,.90 if mobile else .90,'December 2015 to December 2025\nU.S. city-average CPI-U, not seasonally adjusted',fontsize=10 if mobile else 12,va='top') values=[float(r['change_pct']) for r in selected] labels=[textwrap.fill(r['category'],21 if mobile else 36) for r in selected] colors=['#21332b' if r['item_code']=='SA0' else '#927144' if float(r['change_pct'])<0 else '#2b7764' for r in selected] ax.barh(range(len(selected)),values,color=colors,height=.65) ax.set_yticks(range(len(selected)),labels,fontsize=12 if mobile else 11) ax.invert_yaxis();ax.axvline(0,color='#67786b',lw=.8) ax.set_xlim((-80,110) if detailed_view else (0,60)) ax.set_xticks([-50,0,50,100] if detailed_view else [0,20,40,60]) ax.xaxis.set_major_formatter(PercentFormatter(100,0));ax.set_xlabel('Cumulative price-index change',fontsize=10 if mobile else 12,labelpad=9) ax.grid(axis='x',alpha=.15);ax.set_axisbelow(True);ax.spines[['top','right','left','bottom']].set_visible(False);ax.tick_params(axis='y',length=0,pad=8) for i,v in enumerate(values): ax.annotate(f'{v:+.1f}%',(0 if mobile and v<0 else v,i),xytext=(4,0),textcoords='offset points',ha='left',va='center',color='#21332b' if mobile or v>=0 else '#ffffff',fontsize=12 if mobile else 11) if detailed_view: ax.axhline(9.5,color='#d3dacb',lw=1) note='Top 10 increases and five largest declines among 373 comparable series.\nCategories overlap; these are not contributions to overall inflation.\nTechnology indexes reflect quality adjustment, not just sticker prices.' else: note='Eight broad groups and the all-items benchmark.\nChanges cover ten years; they are not annual inflation rates.' if mobile: note='\n'.join(textwrap.fill(s,55) for s in note.split('\n')) footer=note+'\nSource: BLS retained CPI-U edition; Actually Clean Data calculations.\nactuallycleandata.com ยท Published November 25, 2026' fig.text(.035,.025,footer,fontsize=10,linespacing=1.4) name=kind+('-mobile' if mobile else '') fig.savefig(destination/(name+'.svg'),metadata={'Date':None,'Creator':'Actually Clean Data'}) if not mobile:fig.savefig(destination/(name+'.png'),dpi=160) plt.close(fig) if __name__=='__main__': render()