codex/past-exam-of-the-mathematics-course-of-the-university-of-cambridge/2005/iii/paper-2-sp4-split-weights.py

past-exam-of-the-mathematics-course-of-the-university-of-cambridge/2005/iii/paper-2-sp4-split-weights.py
"""Draw original weight diagrams; write same-basename opaque PNG to caller CWD."""
from pathlib import Path
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np

plt.rcParams.update({"font.size": 11})
def finish(fig):
    fig.set_facecolor("white")
    fig.tight_layout(rect=(0, .08, 1, 1))
    fig.savefig(Path.cwd()/(Path(__file__).stem+".png"), dpi=130,
                facecolor="white", transparent=False)
    plt.close(fig)

roots=[(2,0),(-2,0),(0,2),(0,-2),(1,1),(1,-1),(-1,1),(-1,-1)]
def panel(ax,weights,title,highest=None):
    ax.set_aspect("equal")
    ax.axhline(0,lw=.8,color="#9faeb8");ax.axvline(0,lw=.8,color="#9faeb8")
    ax.set(xlim=(-2.55,2.55),ylim=(-2.55,2.55),xticks=range(-2,3),yticks=range(-2,3),
           xlabel=r"$L_1$ coefficient",ylabel=r"$L_2$ coefficient",title=title)
    ax.grid(alpha=.15)
    for (x,y),multiplicity in weights.items():
        color="#ae3f35" if highest==(x,y) else "#256c96"
        ax.scatter([x],[y],s=48*multiplicity,color=color,zorder=3)
        ax.annotate(str(multiplicity),(x,y),xytext=(7,8),textcoords="offset points",
                    color=color,fontsize=12)

fig,axes=plt.subplots(1,2,figsize=(10.2,5.0))
symmetric={r:1 for r in roots};symmetric[(0,0)]=2
alternating={(1,1):1,(1,-1):1,(-1,1):1,(-1,-1):1,(0,0):2}
panel(axes[0],symmetric,r"$\mathrm{Sym}^2V$: dimension 10",(2,0))
panel(axes[1],alternating,r"$\Lambda^2V$: dimension 6",(1,1))
fig.text(.5,.018,"Multiplicities shown; the alternating zero space contains the invariant line.",
         ha="center",fontsize=10)
finish(fig)