"""Plot two predeclared count summaries. python -B outer_296_plot.py INPUT_JSON_GZ OUTPUT_SVG"""
import sys,gzip,json
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
with gzip.open(sys.argv[1],'rt') as f:d=json.load(f)['null_tokens']['all']
plt.rcParams.update({'font.family':'DejaVu Sans','svg.fonttype':'none','svg.hashsalt':'lp-296'})
fig,ax=plt.subplots(figsize=(7.2,2.75));fig.subplots_adjust(left=.31,bottom=.23,right=.96,top=.69);fig.patch.set_facecolor('#fbfaf7');ax.set_facecolor('#fbfaf7')
for y,(k,label) in enumerate([('adjacent','Adjacent matches'),('ABA','Outer matches')]):
 v=d[k];lo,hi=v['interval95'];o=v['observed'];ax.plot([lo,hi],[y,y],lw=10,color='#bbd6e1',solid_capstyle='round');ax.plot(v['expected'],y,'|',ms=15,mew=2,c='#2e5465');ax.plot(o,y,'o',ms=8,c='#893c28');ax.annotate(str(o),(o,y),xytext=(0,10),textcoords='offset points',ha='center',color='#73301f',fontsize=10,weight='bold')
ax.set(yticks=[0,1],yticklabels=['Adjacent matches','Outer matches'],xlim=(0,65),ylim=(-.46,1.54),xlabel='Number of complete three-rune words (720 observed)');ax.grid(axis='x',lw=.5,color='#d8d9d6');ax.set_axisbelow(True);ax.tick_params(length=0,pad=6,labelcolor='#293c41');ax.spines[['left','right','top']].set_visible(False);ax.spines['bottom'].set_color('#98a3a1')
fig.text(.045,.92,'Where the manuscript falls among shuffled words',weight='bold',fontsize=15,color='#1a2a2e');fig.text(.045,.805,'Brown dot: manuscript     Blue band: middle 95% of shuffles     Tick: expected count',fontsize=9,color='#344e59');fig.savefig(sys.argv[2],format='svg',metadata={'Date':None,'Title':'Outer and adjacent rune matches in 720 words','Description':'Outer matches: observed 32, shuffled interval 15–34; adjacent matches: observed 10, shuffled interval 35–61.'})
