API Reference
- class Updater(base_file: Union[str, os.PathLike], output_file: Optional[Union[str, os.PathLike]] = None)
- Parameters
base_file – a path to the template file that contains rectangles / images with their respective XML ids set
output_file – the file that will be generated from
base_file
with figures substituted in. If this is none,base_file
will be mutated in palce.
- Returns
Updater
class- ids(self) list[str]
- Returns
A list of available ids belonging to either rect or image objects in the inkscape
base_file
.svg
- layer_names(self) list[str]
Parse all layer names in the document - useful for debugging behavior of hiding / showing layers
- Returns
A list of all layer names in the document
- update(self, map: Dict[str, Union[str, os.PathList]])
update the svg in
base_path
to the png images in the keys ofmap
. All input images must be png encoded. Note that most of the time, you wantplot_figs()
to handle this in a simple manner. The resulting svg file will be stored atoutput_file
.This function may be called more than once for the same
Updater
instance.- Parameters
map – A dictionary of valid XML ids keys and
.png
image path values.- Returns
None
The id of the xml object must be valid. Ensure that it is present in the output of
Updater.ids()
.
- dimensions(id: str) :class:`Dimensions`
fetch the dimensions of the object in inkscape. Note that the output results are in inkscape units, but
matplotlib
figure dimensions are in inches.- Parameters
id – the XML object id whose dimensions we are parsing
- Returns
Dimensions
object with width and height information
- relative_dimensions(id: str, height: float) Tuple[float, float]
A helper method to calculate what width a matplotlib figure should be for a given height, given that you want to preserve the aspect ratio with the geometry from inkscape.
This method simply solves a proportion:
matplotlib width matplotlib height ---------------- = ----------------- inkscape width inkscape height
- Parameters
height – the height of the figure (inches)
- Returns
a tuple of
(width, height)
, ready to be passed into a matplotlibFigure(figsize = _)
constructor
- hide_layers(self, name_or_ids: list[str], method: VisibleMethod = VisibleMethod.Name)
Hide a list of layers from visibility based on names or ids
- Parameters
name_or_ids – a list of strings, containing layer names (default) or layer ids to hide
method – enum value to determine if the list provided is of names or ids
- show_layers(self, name_or_ids: list[str], method: VisibleMethod = VisibleMethod.Name)
Make a list of layers visible based on layer names or ids
- Parameters
name_or_ids – a list of strings, containing layer names (default) or layer ids to show
method – enum value to determine if the list provided is of names or ids
- show_all_layers(self)
Make all layers visible
- hide_all_layers(self)
Make all layers invisible
- to_png(self, output_path: Union[os.PathLike, str], dpi=96)
export the svg generated by
figure_secon
to an output path. The output path may be a png image, or any general export target supported by inkscape.under the hood, this method simply wraps the
inkscape
cli utility in your$PATH
- Parameters
output_path – path to the file to write based on the svg information
dpi – dpi to use for the export, defaults to inkscape’s default value
- class VisibleMethod
- Name
Show or hide layers based on layer name
updater = Updater(...) updater.show_layers(["layer1", "layer2"], method=figure_second.VisibleMethod.Name)
- Id
Show or hide layers based on layer id
updater = Updater(...) updater.show_layers(["layer1", "layer2"], method=figure_second.VisibleMethod.Id)
- class Dimensions
- width(self) float
- Returns
the width of the object (inkscape units)
- height(self) float
- Returns
the height of the object (inkscape units)
- plot_figs(updater: Updater, fig_map: Dict[str, matplotlib.figure.Figure], *args, **kwargs)
Helper function to substitute all figures in the values of
fig_map
into the corresponding inkscape ids inupdater.base_path
.- Parameters
updater – an
Updater()
classfig_map – a dictionary with values matplotlib
Figure
objects, and keys of inkscape ids*args – passed into matplotlib
Figure.savefig
**kwargs – passed into matplotlib
Figure.savefig