"""Optional original figure recipe. Requires an already installed Matplotlib. Reads only offline reproduction outputs; no network or provider actions. """ from pathlib import Path import csv,json,textwrap,xml.etree.ElementTree as ET import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from matplotlib.ticker import PercentFormatter from matplotlib.lines import Line2D BASE=Path(__file__).resolve().parent; OUT=BASE/'outputs' plt.rcParams.update({'font.family':'DejaVu Sans','font.size':12,'svg.fonttype':'none','svg.hashsalt':'firmworkflows-office-size-2023','axes.spines.top':False, 'axes.spines.right':False,'axes.spines.left':False,'axes.edgecolor':'#c6d4d8','axes.labelcolor':'#34515c', 'text.color':'#173540','xtick.color':'#526e78','ytick.color':'#173540','savefig.facecolor':'white'}) LOC='#176879';EMP='#b54c2b';GRID='#dde7ea' SHORT={'541110':'Law offices','541211':'CPA offices','541213':'Tax preparation', '541214':'Payroll services','541219':'Other accounting'} LABELS=['<5','5–9','10–19','20–49','50–99','100–249','250–499','500–999','1,000+'] def legend(): return [Line2D([0],[0],color=LOC,marker='o',lw=2,label='Employer locations'),Line2D([0],[0],color=EMP,marker='D',lw=2,label='Published March employment')] def save(fig,stem,title,description): fig.savefig(OUT/(stem+'.png'),dpi=100,facecolor=fig.get_facecolor()) fig.savefig(OUT/(stem+'.svg'),facecolor=fig.get_facecolor(),metadata={'Date':None,'Creator':'FirmWorkflows; original Matplotlib recipe','Title':title,'Description':description}) p=OUT/(stem+'.svg');root=ET.fromstring(p.read_bytes());ns='http://www.w3.org/2000/svg';ET.register_namespace('',ns) root.set('role','img');root.set('aria-labelledby',stem+'-title '+stem+'-desc') t=ET.Element('{'+ns+'}title',{'id':stem+'-title'});t.text=title d=ET.Element('{'+ns+'}desc',{'id':stem+'-desc'});d.text=description root.insert(0,d);root.insert(0,t);p.write_bytes(ET.tostring(root,encoding='utf-8',xml_declaration=True));plt.close(fig) def main(): summary=list(csv.DictReader((OUT/'industry-summary.csv').open(encoding='utf-8'))) bands=list(csv.DictReader((OUT/'size-bands.csv').open(encoding='utf-8'))) fig=plt.figure(figsize=(14.4,8.2));ax=fig.add_axes([.235,.255,.71,.49]) fig.text(.045,.94,'Small-office shares tell two different stories',fontsize=25,weight='bold') fig.text(.045,.885,'Locations with fewer than 10 March employees · U.S. CBP 2023',fontsize=15,color='#526e78') for i,row in enumerate(summary): y=4-i;n=float(row['under10_establishment_share_percent']);e=float(row['under10_employment_share_percent']) ax.plot([e,n],[y,y],color='#c8d6da',lw=4,zorder=1) ax.scatter(n,y,color=LOC,s=95,zorder=3);ax.scatter(e,y,color=EMP,marker='D',s=80,zorder=3) for value in [n,e]:ax.text(value,y+.19,f'{value:.1f}%',ha='center',fontsize=14,weight='bold') ax.set_yticks(range(5),[SHORT[r['naics']] for r in summary[::-1]],fontsize=15) ax.tick_params(axis='y',length=0,pad=16);ax.set_xlim(-2,102);ax.set_ylim(-.5,4.6) ax.set_xticks([0,25,50,75,100]);ax.xaxis.set_major_formatter(PercentFormatter(100));ax.grid(axis='x',color=GRID);ax.set_axisbelow(True) fig.legend(handles=legend(),loc='upper left',bbox_to_anchor=(.235,.838),frameon=False,ncol=2,fontsize=13) fig.text(.045,.145,'Each percentage uses its own industry total. Employment is published with disclosure noise.',fontsize=12) fig.text(.045,.101,'The <5 class includes locations with no March employees but wages paid at another time in the year.',fontsize=12) fig.text(.045,.053,'Source: U.S. Census Bureau, CBP 2023 U.S. file, all legal forms. Independent FirmWorkflows analysis.',fontsize=11,color='#526e78') save(fig,'under10-location-employment','Under-10 location share versus reported March employment share', 'Five industries, 2023 U.S. employer establishments. Law offices: 86.8% locations and 33.0% employment; CPA offices: 83.5% and 21.2%; tax preparation: 90.0% and 56.3%; payroll: 60.2% and 2.9%; other accounting: 91.5% and 38.0%. Employment has disclosure noise. This measures establishment size and reported payroll employment. All numbers use the fewer-than-ten size classes.') fig=plt.figure(figsize=(14.4,8.4));ax=fig.add_axes([.235,.29,.71,.45]) fig.text(.045,.945,'The midpoint changes when employment supplies the weight',fontsize=22,weight='bold') fig.text(.045,.887,'First size band where cumulative share reaches 50% · U.S. CBP 2023',fontsize=14,color='#526e78') key={label:i for i,(_,label) in enumerate([('<5','Fewer than 5'),('5_9','5–9'),('10_19','10–19'),('20_49','20–49'),('50_99','50–99'),('100_249','100–249'),('250_499','250–499'),('500_999','500–999'),('1000','1,000 or more')])} for i,row in enumerate(summary): y=4-i;n=key[row['published_establishment_median_size_band']];e=key[row['published_employment_weighted_median_size_band']] ax.plot([n,e],[y,y],color='#c8d6da',lw=4);ax.scatter(n,y,color=LOC,s=95,zorder=3);ax.scatter(e,y,color=EMP,marker='D',s=80,zorder=3) ax.text(e,y+.19,LABELS[e]+('*' if row['naics']=='541219' else ''),ha='center',fontsize=13,weight='bold') ax.set_yticks(range(5),[SHORT[r['naics']] for r in summary[::-1]],fontsize=15);ax.tick_params(axis='y',length=0,pad=16) ax.set_xticks(range(9),LABELS,fontsize=11);ax.set_xlim(-.35,8.35);ax.set_ylim(-.5,4.6);ax.grid(axis='x',color=GRID);ax.set_axisbelow(True) ax.set_xlabel('Ordered size categories; the bands have unequal widths',labelpad=12,fontsize=12) fig.legend(handles=legend(),loc='upper left',bbox_to_anchor=(.235,.84),frameon=False,ncol=2,fontsize=13) fig.text(.045,.17,'These are grouped midpoints of released values, rather than exact underlying medians.',fontsize=12) fig.text(.045,.123,'* Other accounting reaches 50.4% through 10–19: close to the boundary, with disclosure noise.',fontsize=12) fig.text(.045,.077,'Payroll employment may be assigned through a payroll office; do not infer an on-site team from this band.',fontsize=12) fig.text(.045,.035,'Source: U.S. Census Bureau, CBP 2023 U.S. file. Independent FirmWorkflows analysis.',fontsize=11,color='#526e78') save(fig,'published-midpoint-size-bands','Published location and employment-weighted midpoint size bands', 'CPA offices: location midpoint fewer than 5, employment-weighted midpoint 50–99. Law offices: fewer than 5 versus 20–49. Tax preparation: fewer than 5 versus 5–9. Payroll services: 5–9 versus 500–999. Other accounting: fewer than 5 versus 10–19. Other accounting crosses halfway at 50.3946%, making its released median band sensitive to noise near that boundary. Ordered categories have unequal widths. This is a descriptive distribution, not a recommended staffing level.') fig,axes=plt.subplots(3,2,figsize=(14.4,13.4));fig.subplots_adjust(left=.075,right=.97,top=.85,bottom=.08,hspace=.66,wspace=.2) fig.text(.045,.956,'The full size profiles behind the two summaries',fontsize=24,weight='bold') fig.text(.045,.915,'Cumulative share through each establishment-size band · U.S. CBP 2023',fontsize=14,color='#526e78') for ax,row in zip(axes.flat,summary): values=[b for b in bands if b['naics']==row['naics']] for field,color,marker in [('cumulative_establishment_share_percent',LOC,'o'),('cumulative_employment_share_percent',EMP,'D')]: points=[(i,float(b[field])) for i,b in enumerate(values) if b[field]!=''] ax.plot([p[0] for p in points],[p[1] for p in points],color=color,marker=marker,lw=2,markersize=4) ax.axhline(50,color='#899fa7',lw=1,ls='--',zorder=0);ax.set_ylim(0,105);ax.set_xlim(-.2,8.2) ax.set_xticks(range(9),LABELS,rotation=35,ha='right',fontsize=9);ax.set_yticks([0,50,100]);ax.yaxis.set_major_formatter(PercentFormatter(100)) ax.grid(axis='y',color=GRID);ax.set_axisbelow(True);ax.set_title(SHORT[row['naics']]+' · '+row['naics'],loc='left',fontsize=14,weight='bold',pad=12) if row['naics']=='541213': ax.text(.98,.08,'Final two bins: N\nCurves stop at last available bin',transform=ax.transAxes,ha='right',fontsize=9,color='#6e4c3e') ax=axes.flat[5];ax.axis('off');ax.legend(handles=legend(),loc='upper left',frameon=False,fontsize=13) notes='Read a column as a size band, not a point estimate of team size.\n\nThe dashed line marks half of the reported total.\n\nTax-preparation values marked N are unavailable. Curves are never completed by subtracting known bins from totals.\n\nEmployment is noise-infused; these curves describe the released data.' ax.text(.02,.7,notes,transform=ax.transAxes,fontsize=12,va='top',linespacing=1.55,wrap=True) fig.text(.045,.025,'Source: U.S. Census Bureau, CBP 2023 U.S. file, all legal forms. Full 45-row table and offline recipe accompany the article.',fontsize=11,color='#526e78') save(fig,'cumulative-size-profiles','Cumulative establishment and published March employment distributions', 'Five paired profiles across nine size bands. Blue counts each employer location once; orange weights by published March employment. A 50% reference supports the grouped midpoint table. The final two tax-preparation bins remain unavailable and are not reconstructed. The accompanying CSV and HTML table provide all published values and flags.') fig=plt.figure(figsize=(12,6.3),facecolor='#112e38');fig.text(.055,.88,'FIRMWORKFLOWS · RESEARCH',color='#79c3c5',fontsize=15,weight='bold') fig.text(.055,.80,'Small offices.\nA different workforce picture.',color='white',fontsize=33,weight='bold',linespacing=1.3,va='top') fig.text(.055,.365,'83.5%',color='#85d4d5',fontsize=58,weight='bold');fig.text(.54,.365,'21.2%',color='#f2ba9a',fontsize=58,weight='bold') fig.text(.06,.267,'of CPA employer locations',color='white',fontsize=18);fig.text(.545,.267,'of reported March employment',color='white',fontsize=18) fig.text(.055,.16,'Both describe the <10 employee size classes · 2023 U.S. Census CBP',color='#c1d7dd',fontsize=14) fig.text(.055,.075,'5 industries · 9 size bands · attributable data and an offline reproduction recipe',color='#c1d7dd',fontsize=13) fig.text(.055,.028,'Employment is published with disclosure noise.',color='#c1d7dd',fontsize=11) save(fig,'share-card','Small CPA offices versus reported employment concentration', '2023 U.S. CBP: CPA employer locations with fewer than 10 March employees represent 83.5% of locations and 21.2% of reported March employment. Employment is published with disclosure noise. This is a historical aggregate distribution; it does not measure current workload.') print(json.dumps({'figures':3,'share_card':[1200,630],'network':False})) if __name__=='__main__':main()