"""Original chosen positioning errors, not measurements of a product. Save to cwd; tested with Python 3.14.4, NumPy 2.3.5, Matplotlib 3.10.7. """ from pathlib import Path import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np forward = np.array([-0.1, 0.0, 0.1, 0.0]) reverse = forward + 2.0 means = [float(np.mean(x)) for x in [forward, reverse]] spread = [float(np.std(x, ddof=1)) for x in [forward, reverse]] assert np.allclose(means, [0, 2]) assert np.allclose(spread, np.sqrt(0.02 / 3)) assert np.isclose(np.std(np.r_[forward, reverse], ddof=1), np.sqrt(8.04 / 7)) plt.rcParams.update({"font.size": 11, "figure.facecolor": "white"}) fig, ax = plt.subplots(figsize=(8, 4.4), dpi=100) fig.subplots_adjust(left=0.18, right=0.96, top=0.79, bottom=0.25) fig.suptitle("Repeatable from one direction, shifted from the other", fontsize=14, y=0.96) ax.axvline(0, color="#777777", linestyle=":", linewidth=1.3) for values, level, color in [(forward, 1, "#1766a0"), (reverse, 0, "#b64f19")]: # Small vertical offsets separate two coincident error readings. ax.scatter(values, level + np.array([-0.06, -0.02, 0.02, 0.06]), color=color, s=46, zorder=3) mean = float(np.mean(values)) ax.errorbar(mean, level + 0.24, xerr=float(np.std(values, ddof=1)), color=color, fmt="|", markersize=12, capsize=5, linewidth=2) ax.annotate("", xy=(2, 0.5), xytext=(0, 0.5), arrowprops={"arrowstyle": "<->", "color": "#333333"}) ax.text(1, 0.57, "Difference of directional means: 2.00 μm", ha="center", fontsize=10) ax.set(xlim=(-0.45, 2.45), ylim=(-0.23, 1.52), xlabel="Measured position − commanded position (μm)", yticks=[0, 1], yticklabels=["From above", "From below"]) ax.spines[["top", "right"]].set_visible(False) ax.grid(axis="x", alpha=0.16) fig.text(0.5, 0.115, "Four chosen returns per direction; each sample standard deviation is 0.0816 μm.", ha="center", fontsize=10) fig.text(0.5, 0.055, "Small bars show mean ± one sample standard deviation, not a certified tolerance.", ha="center", fontsize=10) fig.savefig(Path("positioning-repeatability-direction.png"), facecolor="white") plt.close(fig)