EVE-QELTHA / research /code /make_figures.py
PureOne's picture
Add EVE-QELTHA v4.0 research release, proofs, verification data and manuscript
9427ec0 verified
Raw History Blame Contribute Delete
2.43 kB
#!/usr/bin/env python3
"""Rebuild both final-release figures from the recorded datasets."""
from pathlib import Path
import json
import subprocess
import sys
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
ROOT=Path(__file__).resolve().parents[1]
subprocess.run([sys.executable,str(ROOT/'code/make_supporting_figures.py')],check=True)
c=json.loads((ROOT/'results/critical.json').read_text())
nx=json.loads((ROOT/'results/nexus_uniform.json').read_text())
plt.rcParams.update({'font.family':'DejaVu Sans','font.size':9,
'axes.spines.top':False,'axes.spines.right':False})
fig,axes=plt.subplots(3,1,figsize=(6.3,7.3),constrained_layout=True)
taus=np.logspace(-1,5,400)
for j,color in [(1,'#136d87'),(2,'#67499c')]:
axes[0].semilogx(taus,taus/(taus+(2*np.pi*j)**2),color=color,label=f'Frequency j={j}')
axes[0].set_xlabel(r'Critical ratio $\tau=\rho/n^2$')
axes[0].set_ylabel(r'$D_{\tau,jj}$');axes[0].set_title('Exact critical frequency filter')
axes[0].legend(fontsize=8)
for case,color in zip([q for q in c['cases'] if q['kind']=='mixed'],['#136d87','#67499c','#9b425a','#7c7f34']):
axes[1].loglog([r['n'] for r in case['rows']],
[r['relative_error_to_effective_response'] for r in case['rows']],
'o-',ms=4,color=color,label=r'$\tau='+str(int(case['tau']))+'$')
axes[1].set_xlabel(r'Spatial frequency $n$');axes[1].set_ylabel('Relative response error')
axes[1].set_title('Full mixed-matrix model approaches the critical law')
axes[1].legend(fontsize=8,ncol=2)
for strength,label,color in [(0.,'No added port','#136d87'),(1e8,r'$\lambda=10^8$','#67499c'),('infinity','Hard constraint','#9b425a')]:
rows=[r for r in nx['rows'] if r['kind']=='balanced' and r['strength']==strength and 'check' not in r]
axes[2].semilogx([r['epsilon'] for r in rows],[r['scaled_capacity'] for r in rows],
'o-',ms=4,color=color,label=label)
axes[2].axhline(3,color='#17243c',ls='--',lw=1)
axes[2].invert_xaxis();axes[2].set_xlabel(r'Twist strength $\varepsilon$')
axes[2].set_ylabel(r'$\kappa/\varepsilon$');axes[2].set_title('Balanced ports share one leading capacity')
axes[2].legend(fontsize=8,ncol=3)
for ax in axes:ax.grid(alpha=.15)
out=ROOT/'figures';out.mkdir(exist_ok=True)
fig.savefig(out/'critical_results.pdf');fig.savefig(out/'critical_results.png',dpi=180)
print(out/'critical_results.pdf')