API Reference¤
This section contains the API reference for the bessaplots library. It provides detailed information about the classes, functions, and modules available in the package.
bessaplots
¤
Bessa Plots - Plottting utilities for scientific papers within the Bessa Group
bessaplots_path = '/home/docs/checkouts/readthedocs.org/user_builds/bessaplots/checkouts/latest/src/bessaplots'
module-attribute
¤
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
styles_path = '/home/docs/checkouts/readthedocs.org/user_builds/bessaplots/checkouts/latest/src/bessaplots/styles'
module-attribute
¤
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
stylesheets = {'bessaplots': RcParams({'axes.linewidth': 0.5,'figure.dpi': 600.0,'figure.figsize': [3.3, 2.5],'font.family': ['serif'],'font.serif': ['Times'],'font.size': 8.0,'grid.linewidth': 0.5,'legend.frameon': False,'lines.linewidth': 1.0,'mathtext.fontset': 'dejavuserif','savefig.bbox': None,'savefig.pad_inches': 0.01,'text.usetex': False,'xtick.direction': 'in','xtick.major.size': 3.0,'xtick.major.width': 0.5,'xtick.minor.size': 1.5,'xtick.minor.visible': True,'xtick.minor.width': 0.5,'xtick.top': False,'ytick.direction': 'in','ytick.major.size': 3.0,'ytick.major.width': 0.5,'ytick.minor.size': 1.5,'ytick.minor.visible': True,'ytick.minor.width': 0.5,'ytick.right': False}), 'dissertation': RcParams({'axes.formatter.use_mathtext': False,'axes.formatter.useoffset': False,'axes.labelsize': 10.0,'axes.linewidth': 0.5,'axes.titlesize': 10.0,'figure.dpi': 150.0,'figure.figsize': [5.02, 3.1],'font.family': ['serif'],'font.size': 10.0,'grid.linewidth': 0.5,'legend.fontsize': 9.0,'legend.frameon': False,'lines.linewidth': 1.0,'pgf.preamble': '\\usepackage[utf8]{inputenc}\\usepackage[T1]{fontenc}\\usepackage{microtype}\\usepackage{siunitx}','pgf.rcfonts': False,'pgf.texsystem': 'pdflatex','text.usetex': True,'xtick.direction': 'in','xtick.labelsize': 9.0,'xtick.major.size': 3.0,'xtick.major.width': 0.5,'xtick.minor.size': 1.5,'xtick.minor.visible': True,'xtick.minor.width': 0.5,'xtick.top': False,'ytick.direction': 'in','ytick.labelsize': 9.0,'ytick.major.size': 3.0,'ytick.major.width': 0.5,'ytick.minor.size': 1.5,'ytick.minor.visible': True,'ytick.minor.width': 0.5,'ytick.right': False})}
module-attribute
¤
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)
FigureGrid
¤
Size and save figures for a grid layout with shared axes.
Computes figure dimensions so that every cell in the grid has an
identical axes (plot area) size. When sharey=True the first
column is wider (it retains the y-axis label and tick labels) and
the remaining columns are narrower. When sharex=True the
bottom row is taller (it retains the x-axis label and tick labels)
and the upper rows are shorter.
The gutter parameter controls the visible gap between adjacent
figures. This space lives outside the figures and should be
distributed by \hfill in the LaTeX subfigure environment.
Attributes:
| Name | Type | Description |
|---|---|---|
n_figures |
int
|
Number of figures per row (columns in the grid, must be >= 1). |
paper_size |
str
|
Paper size key from |
span_columns |
bool
|
|
height |
float
|
Axes height as a fraction of axes width (aspect ratio). |
sharey |
bool
|
Share the y-axis: only the first column keeps its y-axis label and tick labels. |
sharex |
bool
|
Share the x-axis: only the bottom row keeps its x-axis label and tick labels. |
ylabel_margin |
float
|
Extra width (inches) reserved for the y-axis label and tick
labels. When |
xlabel_margin |
float
|
Extra height (inches) reserved for the x-axis label and tick
labels on the bottom row (only used when |
gutter |
float
|
Visible gap (inches) between adjacent figures. Distributed
by |
bottom_pad |
float
|
Bottom margin (inches) including x-axis tick labels and label. |
top_pad |
float
|
Top margin (inches) above the axes. |
xtick_overhang |
float
|
Horizontal padding (inches) reserved inside the figure on
either side of the axes so the first and last x-tick labels
— which are centered on their ticks and extend past the
axes frame — are not cropped by the saved bounding box.
Applied to the right edge of every column and the left edge
of every non-first column; the first column's left edge is
already covered by |
Source code in src/bessaplots/save_figure.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 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 | |
axes_width
property
¤
Axes (plot area) width (inches), identical for all.
bottom_pad = 0.38
class-attribute
¤
Convert a string or number to a floating point number, if possible.
fig_height
property
¤
Figure height (inches) for the bottom row.
first_width
property
¤
Figure width (inches) for the first column.
gutter = 0.06
class-attribute
¤
Convert a string or number to a floating point number, if possible.
height = 0.8
class-attribute
¤
Convert a string or number to a floating point number, if possible.
inner_row_height
property
¤
Figure height (inches) for non-bottom rows.
Equal to :attr:fig_height when sharex=False.
paper_size = 'letter'
class-attribute
¤
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
rest_width
property
¤
Figure width (inches) for non-first columns.
sharex = False
class-attribute
¤
bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
sharey = True
class-attribute
¤
bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
span_columns = False
class-attribute
¤
bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
textwidth_fractions
property
¤
Figure widths as fractions of \textwidth.
Returns a list of length n_figures. When sharey=True
the first entry is larger than the rest. The remaining
fraction is gutter space distributed by \hfill in LaTeX.
top_pad = 0.05
class-attribute
¤
Convert a string or number to a floating point number, if possible.
xlabel_margin = 0.33
class-attribute
¤
Convert a string or number to a floating point number, if possible.
xtick_overhang = 0.1
class-attribute
¤
Convert a string or number to a floating point number, if possible.
ylabel_margin = 0.45
class-attribute
¤
Convert a string or number to a floating point number, if possible.
apply(fig: Figure, first_column: bool = True, last_row: bool = True) -> Figure
¤
Apply grid sizing to fig.
Sets figure dimensions and subplots_adjust margins so that
the axes occupies the same absolute rectangle in every figure.
Strips y-axis decorations when sharey=True and
first_column is False; strips x-axis decorations when
sharex=True and last_row is False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
The matplotlib figure to resize. |
required |
first_column
|
bool
|
|
True
|
last_row
|
bool
|
|
True
|
Returns:
| Type | Description |
|---|---|
Figure
|
The same figure, mutated in place. |
Source code in src/bessaplots/save_figure.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 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 | |
save(fig: Figure, path: str, first_column: bool = True, last_row: bool = True, format: str = 'pgf') -> None
¤
Apply sizing and save with deterministic bounding box.
Calls :meth:apply then saves with bbox_inches set to
the figure's full bbox so the output file has the exact
computed dimensions. The explicit bbox is required (rather
than None) because matplotlib maps
bbox_inches=None to the savefig.bbox rcParam, which
some styles set to "tight" — that would crop the output
to content-dependent dimensions and break grid alignment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
Figure to save. |
required |
path
|
str
|
Output path (extension replaced by format). |
required |
first_column
|
bool
|
|
True
|
last_row
|
bool
|
|
True
|
format
|
str
|
Output format (default |
'pgf'
|
Source code in src/bessaplots/save_figure.py
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 | |
FigureSaver
¤
Source code in src/bessaplots/save_figure.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
SUPPORTED_FORMATS = ('pdf', 'pgf')
class-attribute
¤
Built-in immutable sequence.
If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.
If the argument is a tuple, the return value is the same object.
format = 'pdf'
class-attribute
¤
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
load(path: str) -> Figure
staticmethod
¤
Load a figure from a file.
Source code in src/bessaplots/save_figure.py
121 122 123 124 125 | |
set_format(fmt: str) -> None
classmethod
¤
Set the output format for store/load operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmt
|
str
|
File format. Must be one of |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fmt is not a supported format. |
Source code in src/bessaplots/save_figure.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
store(object: Figure, path: str) -> str
staticmethod
¤
Store a figure at its exact set_size_inches dimensions.
Passes the figure's full bbox explicitly so a
savefig.bbox : tight rcParam in the active style cannot
crop the output to content-dependent dimensions.
Source code in src/bessaplots/save_figure.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
TypstReport
¤
Builder for Typst-based PDF reports.
Accumulates paragraphs and figure grids, then renders them to a
.typ source file and optionally compiles to PDF via the
typst CLI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Report title. Empty string omits the title block entirely.
The default is |
''
|
author
|
str
|
Author name shown below the title. Ignored when title is empty.
The default is |
''
|
date
|
str or None
|
Date string shown below the author. |
None
|
paper_size
|
str
|
One of |
'a4'
|
Examples:
>>> from bessaplots import TypstReport
>>> r = TypstReport(title="My Report", author="J. Doe")
>>> r.add_paragraph("Introduction.")
>>> r.add_figures(["fig1.pdf", "fig2.pdf"], columns=2)
>>> r.save("report") # writes report.typ + compiles report.pdf
Source code in src/bessaplots/typst_report.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 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 | |
author = ''
class-attribute
¤
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
paper_size = 'a4'
class-attribute
¤
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
title = ''
class-attribute
¤
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
add_figures(paths: list[str | pathlib.Path], columns: int | list[str] = 1, caption: str | None = None, gutter: str = '1em', subcaptions: list[str] | None = None, rows_per_page: int | None = None) -> None
¤
Add a grid of figures to the report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
list of str or Path
|
Paths to the figure files (e.g. PDF or PNG). Each path is
resolved to an absolute POSIX path so the generated |
required |
columns
|
int or list of str
|
Number of equal-width columns ( |
1
|
caption
|
str or None
|
When provided, wraps the grid in a Typst |
None
|
gutter
|
str
|
Typst |
'1em'
|
subcaptions
|
list of str or None
|
Per-figure captions. When provided, each image is wrapped
in its own |
None
|
rows_per_page
|
int or None
|
Maximum number of rows per page. When provided, the
figures are split into multiple grids separated by
|
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/bessaplots/typst_report.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | |
add_paragraph(text: str) -> None
¤
Add a paragraph of text to the report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Plain text or Typst markup passed through verbatim.
Special Typst characters ( |
required |
Source code in src/bessaplots/typst_report.py
318 319 320 321 322 323 324 325 326 327 328 329 | |
compile(typ_path: str | pathlib.Path, pdf_path: str | pathlib.Path | None = None) -> Path
¤
Compile a .typ file to PDF using the typst CLI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
typ_path
|
str or Path
|
Path to the |
required |
pdf_path
|
str or Path or None
|
Output PDF path. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the compiled PDF. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the |
Source code in src/bessaplots/typst_report.py
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 | |
save(stem: str | pathlib.Path) -> Path
¤
Write the .typ file and compile it to PDF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stem
|
str or Path
|
Base name (without extension) for the output files.
Produces |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the compiled PDF. |
Source code in src/bessaplots/typst_report.py
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | |
write(path: str | pathlib.Path) -> Path
¤
Write the .typ source file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Destination path. The |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Absolute path to the written |
Source code in src/bessaplots/typst_report.py
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 | |
read_styles_in_folders(root_path)
¤
Reads all stylesheets in the given path and its subfolders.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_path
|
str
|
Path to the root folder containing the stylesheets and other subfolders with stylesheets. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
stylesheets |
dict
|
Dictionary of stylesheets in the form of {style_name: rcParams}. Should be compatible with matplotlib's plt.style.library dictionary. |
Source code in src/bessaplots/styles_discovery.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
savefig(fig: Figure, path: str, n_side_by_side=1, span_columns=False, height=0.8, paper_size: str = 'letter', format: str = 'pdf') -> None
¤
Saves a figure scaled exactly for an IEEE subfigure slot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
The matplotlib figure object. |
required |
path
|
str
|
The storage location (including file name) for the figure. The .pdf suffix is added automatically. |
required |
n_side_by_side
|
int
|
How many figures will sit horizontally (1, 2, or 3). The default is 1. |
1
|
span_columns
|
bool
|
False for single column (3.48"), True for full page (7.14"). The default is False. |
False
|
height
|
float
|
The height of the figure as a fraction of the width. The default is 0.8. |
0.8
|
paper_size
|
str
|
The paper size ("letter", "a4", "b5"). The default is "letter". |
'letter'
|
format
|
str
|
The file format to save (e.g., "pdf", "png"). The default is "pdf". |
'pdf'
|
Source code in src/bessaplots/save_figure.py
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 | |
set_size(fig: Figure, n_side_by_side=1, span_columns=False, height: float = 0.8, paper_size: str = 'letter', subplot_adjust: dict | None = None) -> Figure
¤
Set figure size to fit in IEEE column layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
The matplotlib figure object. |
required |
n_side_by_side
|
int
|
How many figures will sit horizontally (1, 2, or 3). The default is 1. |
1
|
span_columns
|
bool
|
False for single column (3.48"), True for full page (7.14"). The default is False. |
False
|
height
|
float
|
The height of the figure as a fraction of the width. The default is 0.8. |
0.8
|
paper_size
|
str
|
The paper size ("letter", "a4", "b5"). The default is "letter". |
'letter'
|
subplot_adjust
|
dict
|
Optional dictionary of subplot adjustments to pass to
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
The matplotlib figure object with the new size. |
Source code in src/bessaplots/save_figure.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
FigureGrid¤
bessaplots.FigureGrid
¤
Size and save figures for a grid layout with shared axes.
Computes figure dimensions so that every cell in the grid has an
identical axes (plot area) size. When sharey=True the first
column is wider (it retains the y-axis label and tick labels) and
the remaining columns are narrower. When sharex=True the
bottom row is taller (it retains the x-axis label and tick labels)
and the upper rows are shorter.
The gutter parameter controls the visible gap between adjacent
figures. This space lives outside the figures and should be
distributed by \hfill in the LaTeX subfigure environment.
Attributes:
| Name | Type | Description |
|---|---|---|
n_figures |
int
|
Number of figures per row (columns in the grid, must be >= 1). |
paper_size |
str
|
Paper size key from |
span_columns |
bool
|
|
height |
float
|
Axes height as a fraction of axes width (aspect ratio). |
sharey |
bool
|
Share the y-axis: only the first column keeps its y-axis label and tick labels. |
sharex |
bool
|
Share the x-axis: only the bottom row keeps its x-axis label and tick labels. |
ylabel_margin |
float
|
Extra width (inches) reserved for the y-axis label and tick
labels. When |
xlabel_margin |
float
|
Extra height (inches) reserved for the x-axis label and tick
labels on the bottom row (only used when |
gutter |
float
|
Visible gap (inches) between adjacent figures. Distributed
by |
bottom_pad |
float
|
Bottom margin (inches) including x-axis tick labels and label. |
top_pad |
float
|
Top margin (inches) above the axes. |
xtick_overhang |
float
|
Horizontal padding (inches) reserved inside the figure on
either side of the axes so the first and last x-tick labels
— which are centered on their ticks and extend past the
axes frame — are not cropped by the saved bounding box.
Applied to the right edge of every column and the left edge
of every non-first column; the first column's left edge is
already covered by |
Source code in src/bessaplots/save_figure.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 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 | |
axes_width
property
¤
Axes (plot area) width (inches), identical for all.
bottom_pad = 0.38
class-attribute
¤
Convert a string or number to a floating point number, if possible.
fig_height
property
¤
Figure height (inches) for the bottom row.
first_width
property
¤
Figure width (inches) for the first column.
gutter = 0.06
class-attribute
¤
Convert a string or number to a floating point number, if possible.
height = 0.8
class-attribute
¤
Convert a string or number to a floating point number, if possible.
inner_row_height
property
¤
Figure height (inches) for non-bottom rows.
Equal to :attr:fig_height when sharex=False.
paper_size = 'letter'
class-attribute
¤
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
rest_width
property
¤
Figure width (inches) for non-first columns.
sharex = False
class-attribute
¤
bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
sharey = True
class-attribute
¤
bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
span_columns = False
class-attribute
¤
bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
textwidth_fractions
property
¤
Figure widths as fractions of \textwidth.
Returns a list of length n_figures. When sharey=True
the first entry is larger than the rest. The remaining
fraction is gutter space distributed by \hfill in LaTeX.
top_pad = 0.05
class-attribute
¤
Convert a string or number to a floating point number, if possible.
xlabel_margin = 0.33
class-attribute
¤
Convert a string or number to a floating point number, if possible.
xtick_overhang = 0.1
class-attribute
¤
Convert a string or number to a floating point number, if possible.
ylabel_margin = 0.45
class-attribute
¤
Convert a string or number to a floating point number, if possible.
apply(fig: Figure, first_column: bool = True, last_row: bool = True) -> Figure
¤
Apply grid sizing to fig.
Sets figure dimensions and subplots_adjust margins so that
the axes occupies the same absolute rectangle in every figure.
Strips y-axis decorations when sharey=True and
first_column is False; strips x-axis decorations when
sharex=True and last_row is False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
The matplotlib figure to resize. |
required |
first_column
|
bool
|
|
True
|
last_row
|
bool
|
|
True
|
Returns:
| Type | Description |
|---|---|
Figure
|
The same figure, mutated in place. |
Source code in src/bessaplots/save_figure.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 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 | |
save(fig: Figure, path: str, first_column: bool = True, last_row: bool = True, format: str = 'pgf') -> None
¤
Apply sizing and save with deterministic bounding box.
Calls :meth:apply then saves with bbox_inches set to
the figure's full bbox so the output file has the exact
computed dimensions. The explicit bbox is required (rather
than None) because matplotlib maps
bbox_inches=None to the savefig.bbox rcParam, which
some styles set to "tight" — that would crop the output
to content-dependent dimensions and break grid alignment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
Figure to save. |
required |
path
|
str
|
Output path (extension replaced by format). |
required |
first_column
|
bool
|
|
True
|
last_row
|
bool
|
|
True
|
format
|
str
|
Output format (default |
'pgf'
|
Source code in src/bessaplots/save_figure.py
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 | |
TypstReport¤
bessaplots.TypstReport
¤
Builder for Typst-based PDF reports.
Accumulates paragraphs and figure grids, then renders them to a
.typ source file and optionally compiles to PDF via the
typst CLI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Report title. Empty string omits the title block entirely.
The default is |
''
|
author
|
str
|
Author name shown below the title. Ignored when title is empty.
The default is |
''
|
date
|
str or None
|
Date string shown below the author. |
None
|
paper_size
|
str
|
One of |
'a4'
|
Examples:
>>> from bessaplots import TypstReport
>>> r = TypstReport(title="My Report", author="J. Doe")
>>> r.add_paragraph("Introduction.")
>>> r.add_figures(["fig1.pdf", "fig2.pdf"], columns=2)
>>> r.save("report") # writes report.typ + compiles report.pdf
Source code in src/bessaplots/typst_report.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 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 | |
author = ''
class-attribute
¤
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
paper_size = 'a4'
class-attribute
¤
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
title = ''
class-attribute
¤
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
add_figures(paths: list[str | pathlib.Path], columns: int | list[str] = 1, caption: str | None = None, gutter: str = '1em', subcaptions: list[str] | None = None, rows_per_page: int | None = None) -> None
¤
Add a grid of figures to the report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
list of str or Path
|
Paths to the figure files (e.g. PDF or PNG). Each path is
resolved to an absolute POSIX path so the generated |
required |
columns
|
int or list of str
|
Number of equal-width columns ( |
1
|
caption
|
str or None
|
When provided, wraps the grid in a Typst |
None
|
gutter
|
str
|
Typst |
'1em'
|
subcaptions
|
list of str or None
|
Per-figure captions. When provided, each image is wrapped
in its own |
None
|
rows_per_page
|
int or None
|
Maximum number of rows per page. When provided, the
figures are split into multiple grids separated by
|
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/bessaplots/typst_report.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | |
add_paragraph(text: str) -> None
¤
Add a paragraph of text to the report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Plain text or Typst markup passed through verbatim.
Special Typst characters ( |
required |
Source code in src/bessaplots/typst_report.py
318 319 320 321 322 323 324 325 326 327 328 329 | |
compile(typ_path: str | pathlib.Path, pdf_path: str | pathlib.Path | None = None) -> Path
¤
Compile a .typ file to PDF using the typst CLI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
typ_path
|
str or Path
|
Path to the |
required |
pdf_path
|
str or Path or None
|
Output PDF path. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the compiled PDF. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the |
Source code in src/bessaplots/typst_report.py
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 | |
save(stem: str | pathlib.Path) -> Path
¤
Write the .typ file and compile it to PDF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stem
|
str or Path
|
Base name (without extension) for the output files.
Produces |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the compiled PDF. |
Source code in src/bessaplots/typst_report.py
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | |
write(path: str | pathlib.Path) -> Path
¤
Write the .typ source file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Destination path. The |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Absolute path to the written |
Source code in src/bessaplots/typst_report.py
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 | |