# Colored scatter plots of port quadrature fields import pandas as pd import numpy as np import matplotlib.pyplot as plt from pathlib import Path # Load CSV csv_path = Path("./port_quadrature_export.csv") df = pd.read_csv(csv_path) # Compute magnitudes df["Et_mag"] = np.sqrt(df["Et_x"]**2 + df["Et_y"]**2 + df["Et_z"]**2) df["Ht_mag"] = np.sqrt(df["Ht_x"]**2 + df["Ht_y"]**2 + df["Ht_z"]**2) # Example: scatter color-coded by |Et| for all quadrature points plt.figure(figsize=(7,6)) sc = plt.scatter(df["x"], df["y"], c=df["Et_mag"], cmap="viridis", s=50) plt.colorbar(sc, label="|Et| magnitude") plt.xlabel("x") plt.ylabel("y") plt.title("Tangential E-field magnitude (all faces)") plt.axis("equal") plt.show() # Example: scatter color-coded by |Ht| plt.figure(figsize=(7,6)) sc = plt.scatter(df["x"], df["y"], c=df["Ht_mag"], cmap="plasma", s=50) plt.colorbar(sc, label="|Ht| magnitude") plt.xlabel("x") plt.ylabel("y") plt.title("Tangential H-field magnitude (all faces)") plt.axis("equal") plt.show() # Example: per-face plotting (loop through faces) for (face_id, local_idx), face_df in df.groupby(["exc_face_id", "local_face_idx"]): plt.figure(figsize=(6,5)) sc = plt.scatter(face_df["x"], face_df["y"], c=face_df["Et_mag"], cmap="viridis", s=60) plt.colorbar(sc, label="|Et|") plt.xlabel("x") plt.ylabel("y") plt.title(f"Face {face_id}-{local_idx} |Et|") plt.axis("equal") plt.show() # break after one or two faces to avoid too many plots break