def main(argv: list[str] | None = None) -> None:
"""Plot the showcase grid, or save it to the file named on the command line."""
try:
from .plotting import Panel, plot_grid
except ImportError:
raise SystemExit("The demo needs matplotlib: pip install 'geomotif[plot]'") from None
args = sys.argv[1:] if argv is None else argv
panels: list[Panel] = []
for title, motif, spacing in EXAMPLES:
# A dense equal-spaced copy of the same geometry is drawn as the
# smooth guide line under the sample points.
extra = {"center": motif.center, "guide": motif.generate(800)}
panels.append((title, motif.generate(120, spacing=spacing), extra))
fig = plot_grid(
panels,
ncols=2,
suptitle="geomotif demo",
show_points=True,
label_endpoints=True,
)
if args:
out = args[0]
fig.savefig(out, dpi=150, facecolor=fig.get_facecolor())
print(f"saved {out}")
return
import matplotlib
import matplotlib.pyplot as plt
# File-only backends can't open a window; fall back to saving a PNG
# instead of show()ing into the void.
if matplotlib.get_backend().lower() in {
"agg",
"pdf",
"ps",
"svg",
"pgf",
"template",
"cairo",
}:
out = "spiral-demo.png"
fig.savefig(out, dpi=150, facecolor=fig.get_facecolor())
print(
f"No GUI backend available for matplotlib — saved {out} instead.\n"
"To get an interactive window, install one of:\n"
" pip install PyQt6 (inside this venv)\n"
" your OS's Tk package (e.g. 'sudo pacman -S tk', "
"'sudo apt install python3-tk')"
)
else:
plt.show()