Plot several parameter cases in one run

Replace the single A/B/C constants and --x0 option with a CASES table;
each case writes <name>.png and <name>.pdf. Add the A = diag(2, 0.75),
x0 = (0, -0.6) case.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
loicvhandClaude Opus 5 committed 2026-09-15 20:54:21 +02:00
1 parent b2b782394a
commit 72c19852d8
2 files changed
+23 -13

No files matched your search

+4 -3
View File
@@ -12,11 +12,12 @@ The figure shows the trajectory in the plane, `f(mu) = psi(x(mu))`, the distance
## Usage
pip install -r requirements.txt
python plot_mu_trajectories.py # degenerate case x0 = (0, -0.1)
python plot_mu_trajectories.py --x0 0.3 0.2 --output figures/generic
python plot_mu_trajectories.py # every case, into figures/
python plot_mu_trajectories.py x_trajectories_mu_2 # a single case
pytest
The ellipse is set by `A`, `B`, `C` at the top of `plot_mu_trajectories.py`.
Cases (`A`, `x0`, and optionally `b` and `c`) are listed in `CASES` at the top of
`plot_mu_trajectories.py`; each one produces `<name>.png` and `<name>.pdf`.
Text is typeset with LaTeX (`text.usetex`) when `latex` is on the `PATH`, with the `cm-super` and
`type1cm` packages; otherwise matplotlib's Computer Modern math font is used.
+19 -10
View File
@@ -19,9 +19,11 @@ from matplotlib.lines import Line2D
from quadric import TOL, Ellipsoid
A = np.array([[2.0, 0.0], [0.0, 1.0]])
B = np.zeros(2)
C = -1.0
# One figure per case, for the ellipse x'Ax + b'x + c = 0 (b = 0 and c = -1 by default).
CASES = {
'x_trajectories_mu_1': dict(A=np.diag([2.0, 1.0]), x0=[0.0, -0.1]),
'x_trajectories_mu_2': dict(A=np.diag([2.0, 0.75]), x0=[0.0, -0.6]),
}
N_PER_BRANCH = 266 # mu samples between consecutive poles
EPS = 0.01 # gap left on each side of a pole
@@ -163,16 +165,23 @@ def use_latex_fonts():
def main():
use_latex_fonts()
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
parser.add_argument('--x0', type=float, nargs=2, default=[0.0, -0.1], metavar=('X1', 'X2'))
parser.add_argument('--output', type=Path, default=Path('figures/x_trajectories_mu'),
help='output path, without extension (a .png and a .pdf are written)')
parser.add_argument('cases', nargs='*', metavar='CASE',
help=f'cases to plot, among {", ".join(CASES)} (default: all)')
parser.add_argument('--output-dir', type=Path, default=Path('figures'))
parser.add_argument('--show', action='store_true')
args = parser.parse_args()
unknown = set(args.cases) - set(CASES)
if unknown:
parser.error(f'unknown cases: {", ".join(sorted(unknown))}')
fig = plot_trajectories(Ellipsoid(A, B, C), np.array(args.x0))
args.output.parent.mkdir(parents=True, exist_ok=True)
for extension in ('.png', '.pdf'):
fig.savefig(args.output.with_name(args.output.name + extension))
args.output_dir.mkdir(parents=True, exist_ok=True)
for name in args.cases or CASES:
case = CASES[name]
Q = Ellipsoid(case['A'], case.get('b', np.zeros(2)), case.get('c', -1.0))
fig = plot_trajectories(Q, np.array(case['x0']))
for extension in ('.png', '.pdf'):
fig.savefig(args.output_dir / (name + extension))
print('wrote', args.output_dir / name)
if args.show:
plt.show()