from pathlib import Path
import pandas as pd,numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
R=Path(__file__).resolve().parent;p=pd.read_csv(R/'pair_diversity.csv');p=p[p.period.isin([str(y) for y in range(2021,2026)])].copy();p['year']=p.period.astype(int);p=p.sort_values('year')
c=pd.read_csv(R/'tag_coverage.csv')
plt.rcParams.update({'font.family':'DejaVu Sans','font.size':11,'axes.spines.top':False,'axes.spines.right':False})
fig,ax=plt.subplots(1,2,figsize=(14,5.8))
ax[0].plot(p.year,100*p.n/p.n.iloc[0],'o-',color='#286c85',label='Released game apps',lw=2)
ax[0].plot(p.year,100*p.expected_pairs_in_3000/p.expected_pairs_in_3000.iloc[0],'o-',color='#bc7848',label='Activity pairs in equal 3,000-game samples',lw=2)
ax[0].set_ylim(90,215);ax[0].set_xticks(p.year);ax[0].set_ylabel('Index: 2021 = 100');ax[0].set_title('Supply grew much faster than comparable label variety',loc='left',fontsize=12,fontweight='bold',pad=15);ax[0].legend(frameon=False,fontsize=9,loc='upper left')
bottom=np.zeros(len(c))
for label,v,color in [('0–5 tags',c.share_le5,'#d7b08c'),('6–14 tags',1-c.share_le5-c.share_ge15,'#b8c8cb'),('15–19 tags',c.share_ge15-c.share_exact20,'#77a1af'),('20 tags',c.share_exact20,'#286c85')]:
    ax[1].bar(c.year,v*100,bottom=bottom,label=label,color=color);bottom+=v*100
ax[1].set_ylim(0,100);ax[1].set_xticks(c.year);ax[1].set_ylabel('Share of games (%)');ax[1].set_title('Older cohorts have much thinner current tag records',loc='left',fontsize=12,fontweight='bold',pad=15);ax[1].legend(frameon=False,fontsize=9,loc='lower right')
fig.suptitle('Steam catalog expansion and advertised variety',x=.04,ha='left',fontsize=17,fontweight='bold');fig.text(.04,.018,'September 5, 2026 snapshot; paid games outside explicit descriptors. Current tags describe storefront positioning, not historical genres or verified creativity.',fontsize=9,color='#555')
fig.tight_layout(rect=[0,.06,1,.92]);fig.savefig(R/'catalog_variety.png',dpi=170);fig.savefig(R/'catalog_variety.svg');plt.close(fig)
