publication
Publication-style plotting helpers (Latin Modern, fixed geometry, PDF export).
Two publication styles share the same fonts, LaTeX labels, and fixed panel
geometry and differ only in palette: "publication" is white, for print, and
"publication_dark" is the dark twin, for slides and for figures shown next
to a viser scene. PDF export is print-oriented and stays white in both.
PublicationFigure
¶
Plotly figure wrapper with Latin Modern show() and matplotlib save_pdf().
Source code in openscvx/plotting/publication.py
apply_latin_modern_to_axis(ax, lm_fp) -> None
¶
Restyle a matplotlib axis' ticks, labels, and title in Latin Modern.
Matplotlib applies a font at draw time per artist, so text created before
the font was chosen keeps the default; call this once an axis is fully
populated. lm_fp is a :func:latin_modern_fontproperties result, and
None (font not installed) leaves the axis untouched.
Source code in openscvx/plotting/publication.py
apply_publication_plotly_layout(fig: go.Figure, *, n_rows: int = 1, n_cols: int = 1, extra_legend_width: int = 0, dark: bool = False, width: int | None = None, height: int | None = None) -> None
¶
Apply Latin Modern fonts, LaTeX-friendly defaults, and fixed size to a figure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
Figure to restyle in place. |
required |
n_rows
|
int
|
Rows in the subplot grid, used to size the figure. |
1
|
n_cols
|
int
|
Columns in the subplot grid, used to size the figure. |
1
|
extra_legend_width
|
int
|
Pixels to add for a legend outside the panels. |
0
|
dark
|
bool
|
Use the dark palette (:func: |
False
|
width
|
int | None
|
Overrides the grid-derived width, in pixels. Pass it for figures whose aspect ratio is set by the data rather than by the panel grid, such as an equal-axis planar trajectory. |
None
|
height
|
int | None
|
Overrides the grid-derived height, in pixels. |
None
|
Source code in openscvx/plotting/publication.py
expand_var_components(result: OptimizationResults, specs: list[VarSpec] | None, variables: list, *, include_private: bool = False) -> list[tuple[str, str, int]]
¶
Expand variable specs into (display_name, var_name, component_idx) entries.
Source code in openscvx/plotting/publication.py
latex_component_label(var_name: str, component: int, *, dim: int | None = None) -> str
¶
Return a LaTeX axis label for a state/control component.
Source code in openscvx/plotting/publication.py
latin_modern_fontproperties()
¶
Matplotlib FontProperties for Latin Modern Roman (PDF export).
Source code in openscvx/plotting/publication.py
parse_var_spec(spec: VarSpec) -> tuple[str, int | None]
¶
Parse a variable spec into (name, component) where component is None for all.
Source code in openscvx/plotting/publication.py
publication_dark_colors() -> dict[str, str]
¶
Surround colors (background, grid, foreground) for "publication_dark".
Figures assembled by hand — matplotlib PDF exports especially — should read
the palette from here rather than respell the hex values, so a dark figure
matches one produced by style="publication_dark".
Source code in openscvx/plotting/publication.py
publication_grid_size(n_rows: int, n_cols: int, *, extra_legend_width: int = 0) -> tuple[int, int]
¶
Return fixed Plotly figure (width, height) in pixels for a subplot grid.
Source code in openscvx/plotting/publication.py
publication_mpl_figsize(n_rows: int, n_cols: int) -> tuple[float, float]
¶
Return fixed matplotlib figsize in inches for a subplot grid.
Source code in openscvx/plotting/publication.py
publication_trace_colors() -> dict[str, str]
¶
Trace colors (trajectory, nodes, bounds, impulses) shared by both publication styles.
save_scp_iterations_pdf(result: OptimizationResults, *, expanded_states: list[dict], expanded_controls: list[dict], n_state_cols: int, n_control_cols: int, n_state_rows: int, n_control_rows: int, n_iterations: int, time_slice, X_prop_history: list | None, path: str | Path, cmap_name: str = 'viridis') -> None
¶
Save SCP iteration overlay plot as a PDF via matplotlib.
Source code in openscvx/plotting/publication.py
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 | |
save_timeseries_pdf(result: OptimizationResults, components: list[tuple[str, str, int]], *, var_list: list, path: str | Path, suptitle: str, cols: int, split_nodes: bool = False, impulsive_fn=None, plot_trajectory_fn=None) -> None
¶
Save state/control time-series subplots as a PDF via matplotlib.
Source code in openscvx/plotting/publication.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 | |
show_plotly_with_latin_modern(fig: go.Figure) -> None
¶
Open a Plotly figure in the browser with Latin Modern for axes and legend.
Source code in openscvx/plotting/publication.py
wrap_publication_figure(fig: go.Figure, *, pdf_path: str | Path | None, default_pdf_name: str, save_fn) -> PublicationFigure | go.Figure
¶
Return a publication wrapper that auto-saves PDF, or the raw figure for dark style.