codexshared-calibration-uncertainty-floor.py
shared-calibration-uncertainty-floor.py
"""Illustrate the uncertainty floor from a common interlaboratory reference.
Python 3.14; NumPy 2.3.5; Matplotlib 3.10.7. Run from the media directory.
This is a stipulated independent-plus-common uncertainty model, not observed data.
"""
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
n=np.unique(np.r_[np.arange(1,101),np.geomspace(101,1000,100).astype(int)])
sigma,u_common=.20,.50
independent=sigma/np.sqrt(n)
combined=np.sqrt(u_common**2+sigma**2/n)
fig,ax=plt.subplots(figsize=(7.5,3.8),facecolor='white')
fig.subplots_adjust(left=.12,right=.97,bottom=.22,top=.8)
ax.semilogx(n,combined,lw=2.5,color='#245b9c',label='Including common reference uncertainty')
ax.semilogx(n,independent,lw=2,color='#9d592d',label='Independent contribution only')
ax.axhline(u_common,color='#63666b',ls='--',lw=1.3,label='Common contribution: 0.50')
p=float(np.sqrt(u_common**2+sigma**2/25))
ax.scatter([25],[p],color='#245b9c',zorder=4)
ax.annotate('25 laboratories: 0.502',xy=(25,p),xytext=(6,.34),
fontsize=10,arrowprops={'arrowstyle':'->','color':'#444'})
ax.set(xlabel='Number of laboratories, n',ylabel='Standard uncertainty (same units as result)',
xlim=(1,1000),ylim=(0,.62))
ax.spines[['right','top']].set_visible(False);ax.grid(alpha=.2)
ax.legend(loc='center right',bbox_to_anchor=(1,.37),fontsize=9,framealpha=.95)
fig.suptitle('A shared calibration contribution does not average away',fontsize=13,y=.96)
fig.text(.5,.83,r'Stipulated model: $u(\bar{x})=\sqrt{0.50^2+0.20^2/n}$',ha='center',fontsize=11)
fig.text(.5,.035,'Independent laboratory errors shrink with n; the common contribution remains.',
ha='center',fontsize=10)
fig.savefig('shared-calibration-uncertainty-floor.png',dpi=120,facecolor='white')