Showing & Exporting¶
figure ¶
Figures, the plot window and export.
A :class:Figure is a titled page of plots. It only stores how to draw itself, so lists of figures are
cheap to create; the plots are rendered when a page is first shown or exported. A figure may offer
several variants (for example the quantity used to color a trajectory), which the plot window offers
in a drop-down and :func:export_figures writes to separate files.
The same :class:PlotWindow is used by the GUI and by :func:show in scripts.
Figure ¶
Figure(
title: str,
render: RenderFunction | None = None,
variants: dict[str, RenderFunction] | None = None,
)
A titled page of plots.
Parameters:
-
title(str) –Title of the page (tab title in the plot window and file name stem on export).
-
render(RenderFunction | None, default:None) –Draws the plots into the given layout.
-
variants(dict[str, RenderFunction] | None, default:None) –Alternatively, several named render functions; the user picks one in a drop-down.
Source code in trajectopy\visualization\figure.py
create_widget ¶
Creates an interactive widget showing the figure (with a variant selector if needed).
Parameters:
-
use_opengl(bool, default:False) –Draw with OpenGL, if available. Much faster for large data sets.
Source code in trajectopy\visualization\figure.py
export ¶
Exports the figure (or one of its variants) to a PNG, JPG or SVG file.
Parameters:
-
path(str) –Output file; the format is derived from the extension.
-
variant(str | None, default:None) –Name of the variant to export. Defaults to the first one.
-
width(int, default:1600) –Width in pixels of raster images.
Source code in trajectopy\visualization\figure.py
PlotWindow ¶
PlotWindow(
figures: Sequence[Figure],
title: str = "Trajectopy",
export_format: str = "png",
export_width: int = 1600,
use_opengl: bool = True,
parent: QWidget | None = None,
)
Bases: QMainWindow
Window showing figures as tabs. Tabs are rendered when they are first opened.
Source code in trajectopy\visualization\figure.py
ensure_app ¶
Returns the running Qt application, creating one if necessary (required before creating plots).
Source code in trajectopy\visualization\figure.py
opengl_available ¶
Whether an OpenGL context can be created (not the case e.g. in some remote sessions and VMs).
Source code in trajectopy\visualization\figure.py
export_figures ¶
export_figures(
figures: Sequence[Figure],
directory: str,
export_format: str = "png",
width: int = 1600,
) -> list[str]
Exports all figures (and all their variants) to image files in directory.
Returns:
-
list[str]–list[str]: Paths of the written files.
Source code in trajectopy\visualization\figure.py
show ¶
show(
figures: Figure | Sequence[Figure],
title: str = "Trajectopy",
block: bool = True,
use_opengl: bool = True,
) -> PlotWindow
Shows figures in a plot window.
Parameters:
-
figures(Figure | Sequence[Figure]) –Figure(s) to show, one tab each.
-
title(str, default:'Trajectopy') –Window title.
-
block(bool, default:True) –Run the Qt event loop until the window is closed (for scripts). Use
Falseif an event loop is already running, e.g. inside a Qt application. -
use_opengl(bool, default:True) –Draw with OpenGL, if available. Much faster for large data sets.
Returns:
-
PlotWindow(PlotWindow) –The window.
Source code in trajectopy\visualization\figure.py
set_theme ¶
Selects the theme for plots created from now on.