"""Illustrate diffusion-only spatial spreading at a fixed travel distance.
Requires numpy and matplotlib. Coefficients are constructed, not fitted data.
"""
from pathlib import Path
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
root=Path(__file__).resolve().parent.parent
navy,orange,teal,red='#16344b','#b95212','#007f87','#d52b3f'
plt.rcParams.update({'font.family':'DejaVu Sans','font.size':16,'text.color':navy,'axes.labelcolor':navy,'xtick.color':navy,'ytick.color':navy})
fig=plt.figure(figsize=(12,9.5),facecolor='white')
fig.text(.07,.95,'More time → more diffusion',fontsize=27,weight='bold')
fig.text(.07,.903,'Same distance • same diffusion coefficient • different travel times',fontsize=17)
x=np.linspace(-2,24,2200)
for bottom,u,t,color,title in [(.54,1,20,orange,'SLOW FLOW'),(.23,4,5,teal,'FASTER FLOW')]:
 ax=fig.add_axes([.085,bottom,.85,.215])
 D=.025
 sigma=np.sqrt(2*D*t)
 y=np.exp(-.5*((x-20)/sigma)**2)/(sigma*np.sqrt(2*np.pi))
 ax.fill_between(x,y,color=color,alpha=.16)
 ax.plot(x,y,color=color,lw=3)
 ax.plot([0],[0],marker='o',color=red,ms=11,clip_on=False,zorder=5)
 ax.axvline(20,ls=':',color='#8fa6b5',lw=1.5)
 ax.set(xlim=(-2,24),ylim=(0,.95),xticks=[0,5,10,15,20],yticks=[])
 for side in ['top','left','right']:ax.spines[side].set_visible(False)
 ax.spines['bottom'].set_color('#9aaeba')
 ax.tick_params(axis='x',labelsize=14)
 ax.text(.01,.86,title,transform=ax.transAxes,color=color,weight='bold',fontsize=18)
 ax.text(.01,.64,f'u = {u} mm/s   →   t = {t} s',transform=ax.transAxes,fontsize=17)
 ax.text(.01,.43,f'Diffusion spread: σ = {sigma:.1f} mm',transform=ax.transAxes,color=color,fontsize=17)
 ax.annotate('',xy=(20-sigma,.12),xytext=(20+sigma,.12),arrowprops={'arrowstyle':'<->','color':color,'lw':2})
 ax.set_xlabel('Distance along the column (mm)',fontsize=15,labelpad=9)
fig.text(.085,.80,'Sharp input at 0 mm; compare when each band center reaches 20 mm.',fontsize=15)
fig.text(.07,.105,'Diffusion adds variance:  Δσ² = 2Dt',fontsize=22,weight='bold')
fig.text(.07,.063,'Four times the travel time → twice the diffusion spreading (σ).',fontsize=17)
fig.text(.07,.025,'Illustrative unretained, diffusion-only model: D = 0.025 mm²/s; equal area under both profiles.',fontsize=12)
fig.savefig(root/'images/van-deemter/longitudinal-diffusion.png',dpi=200,facecolor='white')
plt.close(fig)
