File size: 2,371 Bytes
f3a3f9d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | """Generate the manuscript's explanatory figure from its exact square/octagon formulas."""
from pathlib import Path
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
dest = Path(__file__).resolve().parent
fig, (ax, bx) = plt.subplots(1, 2, figsize=(7.1, 2.45), gridspec_kw={"width_ratios":[.9,1.3]})
navy, teal, ochre, ink = "#243d58", "#007a76", "#b65127", "#354658"
outer = np.arange(8)*np.pi/4
inner = np.arange(4)*np.pi/2 + np.pi/8
for i, a in enumerate(inner):
for b in outer[2*i:2*i+2]:
ax.plot([np.cos(a), np.cos(b)], [np.sin(a), np.sin(b)], color="#a6b8bf", lw=1.1)
ax.scatter(np.cos(outer), np.sin(outer), s=33, facecolors="white", edgecolors=navy, lw=1.5, label="Target (8)", zorder=3)
ax.scatter(np.cos(inner), np.sin(inner), s=34, color=teal, marker="D", label="Source (4)", zorder=4)
ax.set(xlim=(-1.21,1.21), ylim=(-1.18,1.18), aspect="equal")
ax.axis("off")
ax.set_title("Optimal single rotation", fontsize=10.4, color=navy, weight="bold", pad=5)
ax.legend(loc="upper center", bbox_to_anchor=(.5,-.05), ncol=2, frameon=False, handlelength=1, columnspacing=.8, fontsize=8)
phi = np.linspace(0, np.pi/4, 361)
v = 2-np.cos(phi)-np.cos(np.pi/4-phi)
bx.plot(np.rad2deg(phi), v, color=teal, linewidth=2.1, label="Single frame")
bx.axhline(0,color=ochre,lw=1.5,ls="--",label="Mixture of frames")
bx.scatter([22.5],[2-2*np.cos(np.pi/8)],color=teal,s=23)
bx.annotate("0.15224", xy=(22.5, 2-2*np.cos(np.pi/8)), xytext=(22.5,.099), ha="center",
fontsize=8,color=teal,arrowprops={"arrowstyle":"-","color":teal,"lw":.7})
bx.set(xlim=(0,45),ylim=(-.02,.325),xlabel="Rotation angle (degrees)",ylabel="Squared cost", xticks=[0, 11.25, 22.5, 33.75, 45],yticks=[0,.1,.2,.3])
bx.set_xticklabels(["0","11.25","22.5","33.75","45"])
bx.set_title("Transport to the same target",fontsize=10.4,color=navy,weight="bold",pad=6)
bx.legend(loc="upper center",bbox_to_anchor=(.50,1.00),frameon=False,fontsize=8,ncol=1)
bx.spines[["top","right"]].set_visible(False)
for s in ["left","bottom"]:
bx.spines[s].set_color("#a3b2bb")
bx.tick_params(labelsize=8,colors=ink)
bx.xaxis.label.set_size(8); bx.yaxis.label.set_size(8)
fig.subplots_adjust(left=.025,right=.98,bottom=.22,top=.88,wspace=.31)
fig.savefig(dest/"alignment_geometry.pdf", facecolor="white", metadata={"Title":"One rotation and a mixture of rotations"})
|