INNER CODE UNIT · Python
patch
ssebastianmag/hydrogen-wavefunctions · hwf_plots.py:184
patch = P[max(h - 40, 0):h, 0:min(40, w)] # Sample top-left corner patch to gauge brightness
patch_val = np.nanmean(P) if patch.size == 0 else float(np.nanmean(patch))
r, g, b, _ = im.cmap(im.norm(patch_val)) # Compute luminance of patch color
luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b
qn_color = "#ffffff" if luminance < 0.5 else "#000000"
qn_outline = "#000000" if qn_color == "#ffffff" else "#ffffff"
ax.text(
x=0.04, y=0.95, s=f"({wf.n}, {wf.l}, {wf.m})",
transform=ax.transAxes, ha="left", va="top",
fontsize=42, color=qn_color,
path_effects=[patheffects.withStroke(linewidth=3.0, foreground=qn_outline)]
)
# Save and display figure
ts = datetime.now().strftime("%Y%m%d%H%M%S")
filename = f"({wf.n},{wf.l},{wf.m})_{ts}"