# 図: 灯りと同じ高さの帯（1〜2 m）で、投入の横幅 W/r* ごとの「灯りから 3 m 以内に来た割合」と σ（I/B=64 と 400、k=8）
import os; EN=os.environ.get('FIG_LANG')=='en'; T=lambda ja,en: en if EN else ja  # FIG_LANG=en で英語の図（*_en.png）
import json, matplotlib; matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib import font_manager as fm
fp='/mnt/c/Windows/Fonts/YuGothM.ttc'; fm.fontManager.addfont(fp); plt.rcParams['font.family']=[fm.FontProperties(fname=fp).get_name(),'sans-serif']
rows=[json.loads(l) for l in open('lateral_1109.jsonl')]+[json.loads(l) for l in open('lateral2_1109.jsonl')]
fig,axs=plt.subplots(1,2,figsize=(9,3.8))
for IB,c,m in ((16.0,'#9cc3ea','s'),(64.0,'#1f5fa8','o'),(144.0,'#4c8fd6','D'),(400.0,'#c0392b','^')):
    R=[r for r in rows if r['IB']==IB]
    x=[r['W_over_rs'] for r in R]
    axs[0].plot(x,[r['n_ever']/2000 for r in R],marker=m,color=c,lw=2,label=T(f'I/B = {IB:.0f}（r* = {IB**0.5:.0f} m）',f'I/B = {IB:.0f} (r* = {IB**0.5:.0f} m)'))
    axs[1].plot(x,[r['sig_ever']/IB**0.5 for r in R],marker=m,color=c,lw=2,label=f'I/B = {IB:.0f}')
axs[0].set_xlabel(T('投入の横幅 W / r*','injection half-width W / r*')); axs[0].set_ylabel(T('灯りから 3 m 以内に来た割合','fraction coming within 3 m of the lamp')); axs[0].set_ylim(0,1.05)
axs[1].set_xlabel(T('投入の横幅 W / r*','injection half-width W / r*')); axs[1].set_ylabel(T('σ / r*（帯の厚さ 1 m あたりの横の幅 / r*）','σ / r* (lateral width per 1 m of band / r*)'))
axs[0].legend(fontsize=8,frameon=False)
for ax in axs:
    ax.grid(alpha=.25)
    for sp in ('top','right'): ax.spines[sp].set_visible(False)
fig.suptitle(T('灯りと同じ高さを飛ぶ虫の横の到達は I/B = 16〜144 で片側約 2.9〜3.0 r*、I/B = 400 では境目は同じで内側の来る割合が下がる','Insects at lamp height: lateral reach ≈ 2.9–3.0 r* each side for I/B = 16–144; at I/B = 400 the edge is unchanged but fewer arrive inside it'),fontsize=10)
fig.tight_layout(); fig.savefig(T('fig_lateral.png','fig_lateral_en.png'),dpi=150); print('saved')
