utils
AxesListType
module-attribute
Plottable
module-attribute
template
module-attribute
template = "\\documentclass{standalone}\n\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{tikz}\n\\usetikzlibrary{fit,backgrounds,positioning}\n{{- preamble }}\n\n\\begin{document}\n\n\\begin{tikzpicture}\n % Configurable variables\n \\def\\figlist{ {{ figures|join(', ') }} }\n {%- if legendfigure|length %}\n \\def\\legendfig{ {{ legendfigure }} }\n \\def\\legendwidth{ {{ legendwidth }} }\n \\def\\legendtitle{ {{ legendtitle }} }\n {%- endif %}\n \\def\\colstep{ {{ columnstep }} }\n \\def\\rowstep{ {{ rowstep }} }\n \\def\\ncols{ {{ ncols }} }\n \\def\\figurepositions{ { {{ figurepositions|join(', ') }} } }\n \\def\\imgwidth{ {{ imagewidth }} }\n \\def\\labelshow{ {{ labelshow }} }\n \\def\\labeleveryfigure{ {{ labeleveryfigure }} }\n \\def\\rowlabels{ {{ rowlabels }} }\n \\def\\rowlabelposition{ {{ rowlabelposition }} }\n \\def\\columnlabels{ {{ columnlabels }} }\n \\def\\columnlabelposition{ {{ columnlabelposition }} }\n\n \\def\\allnodes{}\n \\foreach \\fname [count=\\n from 0] in \\figlist {\n \\pgfmathsetmacro{\\i}{int(\\figurepositions[int(\\n)]-1)}\n \\pgfmathsetmacro{\\j}{int(\\i+1)}\n \\edef\\basename{fig-\\j}\n\n % Row and column from linear index\n \\pgfmathsetmacro{\\col}{int(mod(\\i, \\ncols))}\n \\pgfmathsetmacro{\\row}{int(\\i / \\ncols)}\n \\pgfmathsetmacro{\\modulo}{int(mod(\\i, \\labeleveryfigure))}\n\n % Place the image using the full file name\n \\node[anchor=south] at (\\col * \\colstep, -\\row * \\rowstep)\n (img-\\basename) {\\IfFileExists{\\fname}{\\includegraphics[width=\\imgwidth]{\\fname}}{\\fbox{\\texttt{Missing \\fname}}}};\n \\xdef\\allnodes{\\allnodes\\space(img-\\basename)}\n\n % Label (a), (b), ...\n \\ifnum\\modulo=0\n \\ifnum\\labelshow=1\n \\node[anchor={{ labelnodeanchor }}, xshift={{ labeloffset[0] }}, yshift={{ labeloffset[1] }}] at (img-\\basename.{{ labelnodeposition }})\n (lab-\\basename) {(\\char\\numexpr {{ labelstart }}+\\n/\\labeleveryfigure\\relax)};\n \\xdef\\allnodes{\\allnodes\\space(lab-\\basename)}\n \\fi\n \\fi\n }\n\n % Annotations for figures\n {{ figureannotations|join('\\n ') }}\n\n % Overall bounding box and legend\n \\node[fit=\\allnodes] (all) {};\n {%- if legendfigure|length %}\n \\IfFileExists{\\legendfig}{\n \\node[anchor={{ legendanchor }}, xshift={{ legendoffset[0] }}, yshift={{ legendoffset[1] }}] (legend) at (all.{{ legendposition }})\n {\\includegraphics[width=\\legendwidth]{\\legendfig}};\n \\node[anchor={{ legendtitleanchor }}, xshift={{ legendtitleoffset[0] }}, yshift={{ legendtitleoffset[1] }}] at (legend.{{ legendtitleposition }}) {\\legendtitle};\n }{}\n {%- endif %}\n\n {%- if customlatexcode|length %}\n % Custom LaTeX code\n {{ customlatexcode }}\n {%- endif %}\n\\end{tikzpicture}\n\n\\end{document}\n\n"
addPrincipleAxis
addPrincipleAxis(
ax: Union["PolarAxes", "MplAxes"],
*,
length: float = 1.15,
arrow_length: float = 0.05,
color: str = "black",
relative: bool = True
) -> "PolarAxes"
Add the principle axis to the polar plot.
| PARAMETER | DESCRIPTION |
|---|---|
ax
|
Polar axes to add the principle axis
TYPE:
|
length
|
Length of the principle axis, by default 1.15
TYPE:
|
arrow_length
|
Length of the arrow, by default 0.05
TYPE:
|
color
|
Color of the principle axis, by default "black"
TYPE:
|
relative
|
Whether the length is relative to the maximum radius, by default True
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PolarAxes
|
Polar axes with the principle axis added |
crop_pdf
crop_pdf(
file: str,
output: str,
rect: tuple[float, float, float, float],
page_numbers: list[int] | None = None,
)
Crop PDF file
| PARAMETER | DESCRIPTION |
|---|---|
file
|
PDF file to be processed.
TYPE:
|
output
|
PDF file to save.
TYPE:
|
rect
|
Rectangle (x1, y1, x2, y2, relative coordinate) to crop
TYPE:
|
page_numbers
|
Page numbers to crop, if None, all pages will be cropped
TYPE:
|
extract_axes
generate_figure_grid
generate_figure_grid(
*figures: str,
output: str,
column_step: str = "4.8cm",
row_step: str = "3.2cm",
image_width: str = "4.0cm",
ncols: int = 2,
legend_figure: str = "",
legend_width: str = "1.5cm",
legend_position: str = "west",
legend_anchor: str = "east",
legend_offset: tuple[str, str] = ("0.0cm", "0.0cm"),
legend_title: str = "",
legend_title_position: str = "north",
legend_title_anchor: str = "south",
legend_title_offset: tuple[str, str] = ("0.0cm", "0.0cm"),
label_show: bool = True,
label_start: str = "a",
label_every_figure: int = 1,
label_position: Literal[
"upper left",
"upper right",
"upper center",
"lower left",
"lower right",
"lower center",
"center left",
"center right",
] = "lower left",
label_offset: tuple[str, str] = ("0.0cm", "0.0cm"),
figure_positions: list[int] | None = None,
figure_annotations: list[tuple[int, str, str, str, str]] | None = None,
preamble: str = "",
custom_latex_code: str = "",
replacements: list[tuple[str, str]] | None = None
)
Generate a grid of figures in a single PDF file.
| PARAMETER | DESCRIPTION |
|---|---|
figures
|
List of figure files to be arranged in a grid.
TYPE:
|
output
|
Output tex file name.
TYPE:
|
column_step
|
Step size between columns, by default "4.8cm"
TYPE:
|
row_step
|
Step size between rows, by default "3.2cm"
TYPE:
|
image_width
|
Width of each image, by default "4.0cm"
TYPE:
|
ncols
|
Number of columns in the grid, by default 2
TYPE:
|
legend_figure
|
Figure file for the legend, by default ""
TYPE:
|
legend_width
|
Width of the legend, by default "1.5cm"
TYPE:
|
legend_position
|
Position for the legend, by default "north"
TYPE:
|
legend_anchor
|
Anchor for the legend, by default "south"
TYPE:
|
legend_offset
|
Offset for the legend, by default ("0.0cm", "0.0cm")
TYPE:
|
legend_title
|
Title for the legend, by default ""
TYPE:
|
legend_title_position
|
Position for the legend title, by default "north"
TYPE:
|
legend_title_anchor
|
Anchor for the legend title, by default "south"
TYPE:
|
legend_title_offset
|
Offset for the legend title, by default ("0.0cm", "0.0cm")
TYPE:
|
label_show
|
Whether to show labels, by default True
TYPE:
|
label_start
|
Start label, by default "a"
TYPE:
|
label_every_figure
|
Add labels to every nth figure, by default 1
TYPE:
|
label_position
|
Position of the label, by default "lower left"
TYPE:
|
label_offset
|
Offset of the label, by default ("0.0cm", "0.0cm")
TYPE:
|
figure_positions
|
List of figure positions in the grid, by default None which means the figures are arranged in order
TYPE:
|
figure_annotations
|
Figure annotations for each figure, by default None. The list of tuples should contain (figure_number (1-based), position, anchor, options, text) for each annotation.
TYPE:
|
preamble
|
Custom LaTeX code in the preamble.
TYPE:
|
custom_latex_code
|
Custom LaTeX code at the end of the tikz figure.
TYPE:
|
replacements
|
Regex for replacements
TYPE:
|
setAxesProps
setAxesProps(
ax: "MplAxes",
*,
unpack_dict: bool = True,
unpack_tuple: bool = True,
**kwargs
) -> None
Set the properties for the axes. For legends, lines with same label will be combined.
| PARAMETER | DESCRIPTION |
|---|---|
ax
|
Axes to set properties
TYPE:
|
unpack_dict
|
Whether to unpack the dict, by default True
TYPE:
|
unpack_tuple
|
Whether to unpack the tuple, by default True
TYPE:
|
kwargs
|
Keyword arguments for the
DEFAULT:
|
setupPiPlane
setupPiPlane(
ax: Union["PolarAxes", "MplAxes"],
*,
length: float = 1.15,
color: str = "black",
arrow_length: float = 0.05,
grid_length: float = 1.05,
show_sectors: bool = False,
sector_position: float = 0.2,
show_xylabel: bool = False,
show_xticks: bool = False,
show_xticklabels: bool = False,
show_yticks: bool = True,
show_yticklabels: bool = False,
yticks_min: float = 0.0,
yticks_max: float = 1.0,
ytiks_num: int = 6,
relative: bool = True
) -> "PolarAxes"
Setup the pi-plane for the polar plot.
| PARAMETER | DESCRIPTION |
|---|---|
ax
|
Polar axes to add the principle axis
TYPE:
|
length
|
Length of the principle axis, by default 1.15
TYPE:
|
color
|
Color of the principle axis, by default "black"
TYPE:
|
arrow_length
|
Length of the arrow, by default 0.05
TYPE:
|
grid_length
|
Length of the grid, by default 1.05
TYPE:
|
show_sectors
|
Whether to show the sectors, by default False
TYPE:
|
sector_position
|
Sector position, by default 0.2
TYPE:
|
yticks_min
|
Minimum value of the yticks, by default 0.0
TYPE:
|
yticks_max
|
Maximum value of the yticks, by default 1.0
TYPE:
|
ytiks_num
|
Number of yticks, by default 6
TYPE:
|
relative
|
Whether the length is relative to the maximum radius, by default True
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PolarAxes
|
Polar axes with the principle axis added |
subplots
subplots(
*args: int,
numfig: int | None = None,
numfig_extra: int = 0,
ncols: int = 2,
subfigsize: Tuple[int | float, int | float] = (6, 4),
figsize: Tuple[int | float, int | float] | None = None,
return_figure: bool = False,
on: Plottable | None = None,
backend: Literal["matplotlib", "bokeh"] | str | None = None,
squeeze: bool = True,
ensure_1d: bool = False,
ensure_2d: bool = False,
clear_unused_axes: bool = True,
numbering: Literal["numeric", "alphabetic"] | None = None,
numbering_title_kwargs: Dict[str, Any] | None = None,
projection: str | Projections | List[Projections] | None = None,
**subplot_kw
) -> AxesListType | Tuple[Figure, AxesListType]
Create (or get) a list of axes (matplotlib) or figures (bokeh) for subplots.
| PARAMETER | DESCRIPTION |
|---|---|
args
|
Positional arguments for the number of figures. If no arguments are given, the number of figures is set to 1.
If one argument is given, it is the number of figures, the number of columns is given by argument
TYPE:
|
numfig
|
Number of figures, by default None which means the number of figures is given by the first argument, higher
priority than
TYPE:
|
numfig_extra
|
Extra number of figures to create, by default 0
TYPE:
|
ncols
|
Number of columns, by default 2
TYPE:
|
subfigsize
|
Subfigure size, by default (6, 4)
TYPE:
|
figsize
|
Figure size, higher priority than
TYPE:
|
return_figure
|
Whether to return the matplotlib figure, by default False
TYPE:
|
on
|
Axes to plot on, by default None
TYPE:
|
backend
|
Backend to use when creating new figures , by default None which means the backend set in the environment
variable
TYPE:
|
squeeze
|
Whether to squeeze the returned axes, by default True.
TYPE:
|
ensure_1d
|
Whether to ensure the returned axes is 1d, by default False
TYPE:
|
ensure_2d
|
Whether to ensure the returned axes is 2d, by default False
TYPE:
|
clear_unused_axes
|
Whether to clear the newly created unused axes, by default True
TYPE:
|
numbering
|
Numbering style for subplots, by default None
TYPE:
|
numbering_title_kwargs
|
Keyword arguments for the title of the numbering, by default None
TYPE:
|
projection
|
Projection for the axes, can be a single projection for all axes or a list of projections for each axes, by default None
TYPE:
|
subplot_kw
|
Keyword arguments for the
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
AxesListType | Tuple[Figure, AxesListType]
|
Depending on the value of
Otherwise, if
In other cases, a list of lists of axes or figures is always returned. If a list of lists of axes or figures should be returned and |