"""Draw the exhaustive survivor count published in literal_230_strict.json; python -B literal_230_figure.py plot.svg"""
import json,sys
from pathlib import Path
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.ticker import FixedLocator,FixedFormatter
from matplotlib import rcParams
D=Path(__file__).resolve().parent;r=json.loads((D/'literal_230_strict.json').read_text())
rcParams.update({'svg.fonttype':'none','svg.hashsalt':'cicada234','font.family':'DejaVu Sans','font.size':10,'axes.spines.top':False,'axes.spines.right':False})
c=[29**4]+r['prefix_key_counts'];fig,ax=plt.subplots(figsize=(7,3.7))
ax.step(range(len(c)),c,where='post',color='#20535f',lw=1.7);ax.set_yscale('log');ax.set_xlabel('Runes read from the beginning of section 8');ax.set_ylabel('Four-position keys remaining')
ax.yaxis.set_major_locator(FixedLocator([1,10,100,1000,10000,100000,1000000]));ax.yaxis.set_major_formatter(FixedFormatter(['1','10','100','1,000','10,000','100,000','1,000,000']))
ax.set_xlim(0,len(c)-1);ax.set_ylim(.74,2e6);ax.grid(axis='y',alpha=.24)
for pos,txt,xy in [(1457,'Only the copying key remains',(1565,22)),(0,'707,281 possible keys',(225,650000))]:
 ax.scatter([pos],[c[pos]],color='#9b3e18',s=24,zorder=4)
 ax.annotate(txt,(pos,c[pos]),xytext=xy,fontsize=9,color='#77351c',arrowprops=dict(arrowstyle='-',color='#9b3e18'))
fig.tight_layout();fig.savefig(sys.argv[1],metadata={'Date':None,'Description':'Four-slot additive keys consistent with the literal plaintext F rule. The last nonidentity key becomes impossible after 1457 of 3316 runes.'})
