### Install from source Source: https://github.com/btel/svg_utils/blob/master/docs/source/getting_started.md Installs the package directly from the source code. ```bash python3 setup.py install ``` ```bash python3 setup.py install --user ``` -------------------------------- ### Install via pip Source: https://github.com/btel/svg_utils/blob/master/docs/source/getting_started.md Installs the package from PyPI. Requires development libraries for libxml2 and libxslt1. ```bash pip3 install svgutils --user ``` ```bash sudo apt-get install libxml2-dev libxslt-dev ``` -------------------------------- ### Install via Conda Source: https://github.com/btel/svg_utils/blob/master/docs/source/getting_started.md Installs the package using the conda-forge channel. ```bash conda config --add channels conda-forge ``` ```bash conda install svgutils ``` ```bash conda install svgutils -c conda-forge ``` -------------------------------- ### Install system dependencies for lxml Source: https://github.com/btel/svg_utils/blob/master/README.rst Install required development libraries for libxml2 and libxslt1 on Debian-based systems. ```bash sudo apt-get install libxml2-dev libxslt-dev ``` -------------------------------- ### Install svgutils via pip Source: https://github.com/btel/svg_utils/blob/master/README.rst Use pip3 to install the package from the Python Package Index. ```bash pip3 install svgutils --user ``` -------------------------------- ### Install pre-commit git hook Source: https://github.com/btel/svg_utils/blob/master/CONTRIBUTING.rst Configures pre-commit to run automatically on every git commit. ```bash pre-commit install ``` -------------------------------- ### Install svgutils via conda Source: https://github.com/btel/svg_utils/blob/master/README.rst Install the package using conda, either from configured channels or by specifying the channel directly. ```bash conda install svgutils ``` ```bash conda install svgutils -c conda-forge ``` -------------------------------- ### Create Simple Figures with compose.Figure Source: https://context7.com/btel/svg_utils/llms.txt A declarative way to create SVG figures. This example shows a basic figure containing a single SVG file. Requires `svgutils.compose`. ```python from svgutils.compose import Figure, SVG, Text, Panel, Image Figure("16cm", "6.5cm", SVG("plot.svg") ).save("simple_figure.svg") ``` -------------------------------- ### Add Text with compose.Text and Defaults Source: https://context7.com/btel/svg_utils/llms.txt Create text elements using global configuration defaults for size, weight, font, and position. Defaults can be overridden per text element. Requires `svgutils.compose`. ```python from svgutils.compose import Figure, Text, CONFIG CONFIG["text.size"] = 12 CONFIG["text.weight"] = "bold" CONFIG["text.font"] = "Helvetica" CONFIG["text.position"] = (10, 20) Figure("10cm", "5cm", Text("Title"), # Uses default position Text("Subtitle", 10, 40, size=10, weight="normal"), # Override defaults Text("Note", 10, 60, size=8, color="gray") ).save("text_example.svg") ``` -------------------------------- ### Run pre-commit hooks Source: https://github.com/btel/svg_utils/blob/master/CONTRIBUTING.rst Executes all pre-commit checks on the project source code. ```bash pip3 install pre-commit pre-commit run --all ``` -------------------------------- ### Stack figures with layout templates Source: https://context7.com/btel/svg_utils/llms.txt Use VerticalLayout or ColumnLayout to stack multiple SVG files automatically. ```python from svgutils.templates import VerticalLayout, ColumnLayout from svgutils.transform import fromfile # Stack figures vertically vertical = VerticalLayout() for filename in ["fig1.svg", "fig2.svg", "fig3.svg"]: svg = fromfile(filename) vertical.add_figure(svg) vertical.save("vertical_stack.svg") # Arrange figures in columns (5 rows per column) column_layout = ColumnLayout(nrows=5, col_width=300, row_height=200) for i in range(12): svg = fromfile(f"plot_{i}.svg") column_layout.add_figure(svg) column_layout.save("column_layout.svg") ``` -------------------------------- ### Iterate Over Panel Elements Source: https://context7.com/btel/svg_utils/llms.txt Demonstrates iterating through the elements contained within a `compose.Panel` object. Requires `svgutils.compose`. ```python from svgutils.compose import Figure, Panel, SVG, Text, Line panel = Panel(SVG("a.svg"), SVG("b.svg")) for element in panel: element.scale(0.9) ``` -------------------------------- ### Draw Lines and Paths with LineElement Source: https://context7.com/btel/svg_utils/llms.txt Create line elements by specifying a list of points. Supports custom width and color. Requires `svgutils.transform`. ```python import svgutils.transform as sg fig = sg.SVGFigure("200px", "200px") points = [(10, 10), (50, 80), (100, 30), (150, 90)] line = sg.LineElement( points=points, width=2, color="red" ) arrow_points = [(20, 150), (180, 150)] arrow = sg.LineElement(arrow_points, width=3, color="blue") fig.append([line, arrow]) fig.save("lines.svg") ``` -------------------------------- ### Load and Transform SVG Files with compose.SVG Source: https://context7.com/btel/svg_utils/llms.txt Load SVG files and apply transformations like scaling, moving, and rotating using chainable methods. Allows configuring default file paths. Requires `svgutils.compose`. ```python from svgutils.compose import Figure, SVG, CONFIG CONFIG["svg.file_path"] = "figures/" Figure("20cm", "10cm", SVG("chart.svg") .scale(0.8) .move(50, 20) .rotate(5), SVG("legend.svg") .scale(0.5) .move(400, 50) ).save("transformed_figure.svg") ``` -------------------------------- ### Create Multi-Panel Figures with compose.Figure Source: https://context7.com/btel/svg_utils/llms.txt Declaratively create figures with multiple panels, each containing an SVG and text annotations. Panels can be positioned and transformed. Requires `svgutils.compose`. ```python from svgutils.compose import Figure, SVG, Text, Panel, Image Figure("16cm", "6.5cm", Panel( SVG("sigmoid_fit.svg"), Text("A", 25, 20, size=12, weight="bold") ), Panel( SVG("anscombe.svg").scale(0.5), Text("B", 25, 20, size=12, weight="bold") ).move(280, 0) ).save("multi_panel_figure.svg") ``` -------------------------------- ### Configure conda channels Source: https://github.com/btel/svg_utils/blob/master/README.rst Add the conda-forge channel to your configuration. ```bash conda config --add channels conda-forge ``` -------------------------------- ### Import compose module Source: https://github.com/btel/svg_utils/blob/master/docs/source/tutorials/composing_multipanel_figures.md Required import for accessing Figure, Panel, SVG, and Text objects. ```python from svgutils.compose import * ``` -------------------------------- ### Group Elements into Panels with compose.Panel Source: https://context7.com/btel/svg_utils/llms.txt Create hierarchical groups of elements (SVGs, Text, Lines) within panels. Panels can be transformed and positioned together. Requires `svgutils.compose`. ```python from svgutils.compose import Figure, Panel, SVG, Text, Line Figure("20cm", "12cm", Panel( SVG("data_plot.svg"), Text("A", 10, 15, size=14, weight="bold"), Line([(10, 25), (100, 25)], width=1, color="gray") ), Panel( SVG("histogram.svg").scale(0.6), Text("B", 10, 15, size=14, weight="bold") ).move(350, 0), Panel( SVG("scatter.svg").scale(0.6), Text("C", 10, 15, size=14, weight="bold") ).move(0, 250) ).save("three_panel_figure.svg") ``` -------------------------------- ### Create and Manipulate SVG Documents Source: https://context7.com/btel/svg_utils/llms.txt Use SVGFigure to initialize, load, append, and save SVG documents. ```python import svgutils.transform as sg # Create a new SVG figure with specified dimensions fig = sg.SVGFigure("16cm", "6.5cm") # Load existing SVG files fig1 = sg.fromfile("plot1.svg") fig2 = sg.fromfile("plot2.svg") # Get the root elements (strips the top-level tag) plot1 = fig1.getroot() plot2 = fig2.getroot() # Position and scale the second plot plot2.moveto(280, 0, scale=0.5) # Append plots to the figure fig.append([plot1, plot2]) # Save the composed figure fig.save("combined_figure.svg") # Get figure size width, height = fig.get_size() print(f"Figure size: {width} x {height}") ``` -------------------------------- ### Add Text Annotations Source: https://context7.com/btel/svg_utils/llms.txt Create and style text elements for figure labeling. ```python import svgutils.transform as sg # Create a new figure fig = sg.SVGFigure("10cm", "8cm") # Create text elements with various styling options label_a = sg.TextElement( x=25, y=20, text="A", size=14, font="Arial", weight="bold", color="black", anchor="start" # "start", "middle", or "end" ) label_b = sg.TextElement( x=200, y=20, text="B", size=14, font="Arial", weight="bold", letterspacing=2, color="#333333" ) # Append text to figure fig.append([label_a, label_b]) fig.save("labeled_figure.svg") ``` -------------------------------- ### Convert Figure to String with compose.Figure Source: https://context7.com/btel/svg_utils/llms.txt Demonstrates converting a composed figure into an SVG string instead of saving it to a file. Requires `svgutils.compose`. ```python from svgutils.compose import Figure, SVG, Text, Panel, Image fig = Figure("10cm", "5cm", SVG("diagram.svg")) svg_string = fig.tostr() ``` -------------------------------- ### Convert SVG to PDF or PNG via Inkscape Source: https://github.com/btel/svg_utils/blob/master/docs/source/tutorials/publication_quality_figures.md Command-line instructions for converting the final SVG output into raster or vector formats using Inkscape. ```bash inkscape --export-pdf=fig_final.pdf fig_final.svg inkscape --export-png=fig_final.png fig_final.svg ``` -------------------------------- ### Define a basic figure Source: https://github.com/btel/svg_utils/blob/master/docs/source/tutorials/composing_multipanel_figures.md Initializes a Figure object with specified dimensions and content. ```python Figure("16cm", "6.5cm", SVG("sigmoid_fit.svg") ) ``` -------------------------------- ### Arrange figures in a grid layout Source: https://context7.com/btel/svg_utils/llms.txt Use the tile method to automatically organize multiple SVG elements into a grid or row structure. ```python from svgutils.compose import Figure, SVG # Arrange 4 plots in a 2x2 grid Figure("20cm", "20cm", SVG("plot1.svg"), SVG("plot2.svg"), SVG("plot3.svg"), SVG("plot4.svg") ).tile(2, 2).save("grid_layout.svg") # Arrange 3 plots in a single row Figure("30cm", "10cm", SVG("a.svg"), SVG("b.svg"), SVG("c.svg") ).tile(3, 1).save("row_layout.svg") ``` -------------------------------- ### Embed Raster Images with compose.Image Source: https://context7.com/btel/svg_utils/llms.txt Embed raster images using a simplified syntax within the `compose` module. Allows configuring default image paths. Requires `svgutils.compose`. ```python from svgutils.compose import Figure, Image, SVG, CONFIG CONFIG["image.file_path"] = "assets/" Figure("10cm", "5cm", SVG("logo.svg").scale(0.2), Image(120, 120, "photo.jpeg").move(150, 0), Image(80, 80, "icon.png").move(300, 20) ).save("mixed_media_figure.svg") ``` -------------------------------- ### Group Elements Together with SVGUtils Source: https://context7.com/btel/svg_utils/llms.txt Demonstrates grouping multiple SVG elements into a single group that can be transformed together. Requires `svgutils.transform`. ```python import svgutils.transform as sg panel = sg.GroupElement([plot1.root, label.root]) panel.moveto(50, 50) panel.rotate(15) final_fig = sg.SVGFigure("20cm", "15cm") final_fig.append(panel) final_fig.save("grouped_elements.svg") ``` -------------------------------- ### SVGFigure - Create and Manipulate SVG Documents Source: https://context7.com/btel/svg_utils/llms.txt The SVGFigure class is used to create new SVG documents or load existing ones. It supports methods for setting dimensions, appending elements, and saving the output. ```APIDOC ## SVGFigure - Create and Manipulate SVG Documents ### Description The `SVGFigure` class is the core container for creating new SVG documents or loading existing ones. It provides methods for setting dimensions, appending elements, and saving the final output. ### Method ```python import svgutils.transform as sg # Create a new SVG figure with specified dimensions fig = sg.SVGFigure("16cm", "6.5cm") # Load existing SVG files fig1 = sg.fromfile("plot1.svg") fig2 = sg.fromfile("plot2.svg") # Get the root elements (strips the top-level tag) plot1 = fig1.getroot() plot2 = fig2.getroot() # Position and scale the second plot plot2.moveto(280, 0, scale=0.5) # Append plots to the figure fig.append([plot1, plot2]) # Save the composed figure fig.save("combined_figure.svg") # Get figure size width, height = fig.get_size() print(f"Figure size: {width} x {height}") ``` ``` -------------------------------- ### fromfile / fromstring - Load SVG Content Source: https://context7.com/btel/svg_utils/llms.txt Load SVG figures from files or strings for manipulation and composition. ```APIDOC ## fromfile / fromstring - Load SVG Content ### Description Load SVG figures from files or strings for manipulation and composition. ### Method ```python import svgutils.transform as sg # Load SVG from a file svg_fig = sg.fromfile("existing_plot.svg") # Load SVG from a string svg_string = ''' ''' svg_from_string = sg.fromstring(svg_string) # Both return SVGFigure objects that can be manipulated root = svg_fig.getroot() root.moveto(50, 50, scale=0.8) ``` ``` -------------------------------- ### Scale and Arrange SVG Elements Source: https://github.com/btel/svg_utils/blob/master/docs/source/tutorials/composing_multipanel_figures.md Scale individual SVG elements using the scale() method before arranging them with tile(). The scale() method takes a single scaling factor argument. ```python Figure("16cm", "6.5cm", SVG("sigmoid_fit.svg"), SVG("anscombe.svg").scale(0.5) ).tile(2, 1) ``` -------------------------------- ### Load SVG Content Source: https://context7.com/btel/svg_utils/llms.txt Load SVG data from files or raw strings into SVGFigure objects. ```python import svgutils.transform as sg # Load SVG from a file svg_fig = sg.fromfile("existing_plot.svg") # Load SVG from a string svg_string = ''' ''' svg_from_string = sg.fromstring(svg_string) # Both return SVGFigure objects that can be manipulated root = svg_fig.getroot() root.moveto(50, 50, scale=0.8) ``` -------------------------------- ### Arrange SVG Elements in a Grid Layout Source: https://github.com/btel/svg_utils/blob/master/docs/source/tutorials/composing_multipanel_figures.md Use the tile() method of Figure() to arrange elements on a regular two-dimensional grid. Specify the number of columns and rows. ```python Figure("16cm", "6.5cm", SVG("sigmoid_fit.svg"), SVG("anscombe.svg") ).tile(2, 1) ``` -------------------------------- ### Group Elements into Panels with Panel() Source: https://github.com/btel/svg_utils/blob/master/docs/source/tutorials/composing_multipanel_figures.md Group related elements like text and SVG drawings into a single unit using the Panel() object. This simplifies applying transformations to multiple elements simultaneously. ```python Figure("16cm", "6.5cm", Panel( Text("A", 25, 20), SVG("sigmoid_fit.svg") ), Panel( Text("B", 25, 20).move(280, 0), SVG("anscombe.svg").scale(0.5) .move(280, 0) ) ) ``` ```python Figure("16cm", "6.5cm", Panel( Text("A", 25, 20), SVG("sigmoid_fit.svg") ), Panel( Text("B", 25, 20), SVG("anscombe.svg").scale(0.5) ).move(280, 0) ) ``` -------------------------------- ### Convert and manipulate SVG units Source: https://context7.com/btel/svg_utils/llms.txt Perform arithmetic and conversions between common measurement units like cm, in, and px. ```python from svgutils.common import Unit # Create units from strings width = Unit("10cm") height = Unit("5in") pixels = Unit("300px") # Convert between units width_in_px = width.to("px") print(f"10cm = {width_in_px.value}px") height_in_cm = height.to("cm") print(f"5in = {height_in_cm.value}cm") # Unit arithmetic double_width = width * 2 half_height = height / 2 print(f"Double: {double_width}, Half: {half_height}") # Supported units: px, cm, mm, pt, in # Conversion factors per inch: px=90, cm=2.54, mm=25.4, pt=72, in=1 ``` -------------------------------- ### TextElement - Add Text Annotations Source: https://context7.com/btel/svg_utils/llms.txt Create text elements with customizable font properties for labeling figures. ```APIDOC ## TextElement - Add Text Annotations ### Description Create text elements with customizable font properties for labeling figures. ### Method ```python import svgutils.transform as sg # Create a new figure fig = sg.SVGFigure("10cm", "8cm") # Create text elements with various styling options label_a = sg.TextElement( x=25, y=20, text="A", size=14, font="Arial", weight="bold", color="black", anchor="start" # "start", "middle", or "end" ) label_b = sg.TextElement( x=200, y=20, text="B", size=14, font="Arial", weight="bold", letterspacing=2, color="#333333" ) # Append text to figure fig.append([label_a, label_b]) fig.save("labeled_figure.svg") ``` ``` -------------------------------- ### Add Grid Overlay with compose.Grid Source: https://context7.com/btel/svg_utils/llms.txt Add a coordinate grid to an SVG figure to aid in element placement during development. Specify grid spacing and label size. Requires `svgutils.compose`. ```python from svgutils.compose import Figure, SVG, Grid Figure("16cm", "10cm", SVG("plot.svg"), Grid(50, 50, size=8) # 50px spacing, 8pt labels ).save("figure_with_grid.svg") ``` -------------------------------- ### Create a multi-panel figure Source: https://github.com/btel/svg_utils/blob/master/docs/source/tutorials/composing_multipanel_figures.md Defines a figure with multiple panels containing SVG files and text annotations. ```python #!/usr/bin/env python3 # coding=utf-8 from svgutils.compose import * Figure( "16cm", "6.5cm", Panel(SVG("sigmoid_fit.svg"), Text("A", 25, 20, size=12, weight="bold")), Panel( SVG("anscombe.svg").scale(0.5), Text("B", 25, 20, size=12, weight="bold") ).move(280, 0), ).save("fig_final_compose.svg") ``` -------------------------------- ### Access SVG Dimensions with compose.SVG Source: https://context7.com/btel/svg_utils/llms.txt Retrieve the width and height of an SVG file loaded via `compose.SVG`. Requires `svgutils.compose`. ```python from svgutils.compose import Figure, SVG, CONFIG svg = SVG("plot.svg") print(f"Width: {svg.width}px, Height: {svg.height}px") ``` -------------------------------- ### from_mpl - Convert Matplotlib Figures to SVG Source: https://context7.com/btel/svg_utils/llms.txt Convert matplotlib figures directly to SVGFigure objects for seamless integration with other SVG elements. ```APIDOC ## from_mpl - Convert Matplotlib Figures to SVG ### Description Convert matplotlib figures directly to SVGFigure objects for seamless integration with other SVG elements. ### Method ```python import matplotlib.pyplot as plt import svgutils.transform as sg # Create a matplotlib figure fig, ax = plt.subplots() ax.plot([1, 2, 3, 4], [1, 4, 2, 3]) ax.set_title("Sample Plot") # Convert to SVGFigure with transparent background svg_fig = sg.from_mpl(fig, savefig_kw={"transparent": True}) # Get the root element for composition plot_element = svg_fig.getroot() # Now combine with other SVG elements combined = sg.SVGFigure("20cm", "10cm") combined.append(plot_element) combined.save("matplotlib_converted.svg") ``` ``` -------------------------------- ### Move and Arrange SVG Elements Source: https://github.com/btel/svg_utils/blob/master/docs/source/tutorials/composing_multipanel_figures.md Position individual SVG elements using their move() method, specifying horizontal and vertical shifts in pixels. Methods can be chained. ```python Figure("16cm", "6.5cm", SVG("sigmoid_fit.svg"), SVG("anscombe.svg").move(280, 0) ) ``` ```python Figure("16cm", "6.5cm", SVG("sigmoid_fit.svg"), SVG("anscombe.svg").scale(0.5) .move(280, 0) ) ``` -------------------------------- ### Add text annotations Source: https://github.com/btel/svg_utils/blob/master/docs/source/tutorials/composing_multipanel_figures.md Overlays text on a figure using the Text object with coordinate and style parameters. ```python Figure("16cm", "6.5cm", Text("A", 25, 20), SVG("sigmoid_fit.svg") ) ``` ```python Figure("16cm", "6.5cm", Text("A", 25, 20, size=12, weight='bold'), SVG("sigmoid_fit.svg") ) ``` -------------------------------- ### Embed Raster Images with ImageElement Source: https://context7.com/btel/svg_utils/llms.txt Embeds raster images (PNG, JPEG) as base64-encoded inline images. Requires reading the image file in binary mode. Requires `svgutils.transform`. ```python import svgutils.transform as sg fig = sg.SVGFigure("15cm", "10cm") with open("photo.png", "rb") as fid: img = sg.ImageElement( stream=fid, width=200, height=150, format="png" ) img.moveto(50, 30) fig.append(img) fig.save("with_embedded_image.svg") ``` -------------------------------- ### Compose SVG Figure Source: https://github.com/btel/svg_utils/blob/master/docs/source/compose.md Use `Figure` to define the canvas size and add scaled SVGs and images. Save the composed figure to a file. ```python Figure( "10cm", "5cm", SVG('svg_logo.svg').scale(0.2), Image(120, 120, 'lion.jpeg').move(120, 0) ).save('test.svg') ``` -------------------------------- ### Convert Matplotlib Figures to SVG Source: https://context7.com/btel/svg_utils/llms.txt Integrate Matplotlib plots into SVG compositions using from_mpl. ```python import matplotlib.pyplot as plt import svgutils.transform as sg # Create a matplotlib figure fig, ax = plt.subplots() ax.plot([1, 2, 3, 4], [1, 4, 2, 3]) ax.set_title("Sample Plot") # Convert to SVGFigure with transparent background svg_fig = sg.from_mpl(fig, savefig_kw={"transparent": True}) # Get the root element for composition plot_element = svg_fig.getroot() # Now combine with other SVG elements combined = sg.SVGFigure("20cm", "10cm") combined.append(plot_element) combined.save("matplotlib_converted.svg") ``` -------------------------------- ### Integrate Matplotlib figures Source: https://context7.com/btel/svg_utils/llms.txt Convert Matplotlib figures into SVG panels for inclusion in a larger composition. ```python import matplotlib.pyplot as plt from svgutils.compose import Figure, MplFigure, Text, Panel # Create matplotlib figures fig1, ax1 = plt.subplots() ax1.plot([1, 2, 3], [1, 4, 2]) fig2, ax2 = plt.subplots() ax2.bar([1, 2, 3], [3, 1, 4]) # Compose with MplFigure Figure("20cm", "10cm", Panel( MplFigure(fig1, transparent=True), Text("A", 10, 15, size=12, weight="bold") ), Panel( MplFigure(fig2, transparent=True), Text("B", 10, 15, size=12, weight="bold") ).move(350, 0) ).save("matplotlib_composition.svg") ``` -------------------------------- ### Fix Matplotlib Units with compose.SVG Source: https://context7.com/btel/svg_utils/llms.txt Load an SVG file generated by Matplotlib and automatically fix its units for proper rendering. Requires `svgutils.compose`. ```python from svgutils.compose import Figure, SVG, CONFIG mpl_svg = SVG("matplotlib_output.svg", fix_mpl=True) ``` -------------------------------- ### Compose SVG figures with svgutils Source: https://github.com/btel/svg_utils/blob/master/docs/source/tutorials/publication_quality_figures.md Uses the svgutils library to load, transform, and combine multiple SVG files into a single figure with added text annotations. ```python import sys import svgutils.transform as sg # create new SVG figure fig = sg.SVGFigure("16cm", "6.5cm") # load matpotlib-generated figures fig1 = sg.fromfile("sigmoid_fit.svg") fig2 = sg.fromfile("anscombe.svg") # get the plot objects plot1 = fig1.getroot() plot2 = fig2.getroot() plot2.moveto(280, 0, scale=0.5) # add text labels txt1 = sg.TextElement(25, 20, "A", size=12, weight="bold") txt2 = sg.TextElement(305, 20, "B", size=12, weight="bold") # append plots and labels to figure fig.append([plot1, plot2]) fig.append([txt1, txt2]) # save generated SVG files fig.save("fig_final.svg") ``` -------------------------------- ### Group Multiple Elements Source: https://context7.com/btel/svg_utils/llms.txt Combine multiple SVG elements into a group for unified transformation. ```python import svgutils.transform as sg # Load SVG files fig1 = sg.fromfile("chart1.svg") fig2 = sg.fromfile("chart2.svg") # Create a group of elements plot1 = fig1.getroot() plot2 = fig2.getroot() label = sg.TextElement(10, 15, "Panel A", size=12, weight="bold") ``` -------------------------------- ### Save a figure to file Source: https://github.com/btel/svg_utils/blob/master/docs/source/tutorials/composing_multipanel_figures.md Uses the save method to export the Figure object to an SVG file. ```python Figure("16cm", "6.5cm", SVG("sigmoid_fit.svg") ).save("fig1.svg") ``` -------------------------------- ### Add a Grid Reference to a Figure Source: https://github.com/btel/svg_utils/blob/master/docs/source/tutorials/composing_multipanel_figures.md Add a Grid() object to a Figure() to generate a grid of lines labelled with pixel positions. This aids in estimating element positions. ```python Figure("16cm", "6.5cm", SVG("sigmoid_fit.svg"), SVG("anscombe.svg").scale(0.5) .move(280, 0), Grid(20, 20) ) ``` -------------------------------- ### GroupElement - Group Multiple Elements Source: https://context7.com/btel/svg_utils/llms.txt Group multiple SVG elements together to apply transformations as a unit. ```APIDOC ## GroupElement - Group Multiple Elements ### Description Group multiple SVG elements together to apply transformations as a unit. ### Method ```python import svgutils.transform as sg # Load SVG files fig1 = sg.fromfile("chart1.svg") fig2 = sg.fromfile("chart2.svg") # Create a group of elements plot1 = fig1.getroot() plot2 = fig2.getroot() label = sg.TextElement(10, 15, "Panel A", size=12, weight="bold") # Example of grouping (actual grouping method not shown in provided text, but implied by class name) # group = sg.GroupElement([plot1, plot2, label]) # group.moveto(10, 10) ``` ``` -------------------------------- ### Combine Multiple SVG Drawings in a Figure Source: https://github.com/btel/svg_utils/blob/master/docs/source/tutorials/composing_multipanel_figures.md Combine multiple SVG drawings by listing them inside the Figure() object. Ensure elements are positioned to avoid overlap. ```python Figure("16cm", "6.5cm", SVG("sigmoid_fit.svg"), SVG("anscombe.svg") ) ``` -------------------------------- ### Transform SVG Elements Source: https://context7.com/btel/svg_utils/llms.txt Apply geometric transformations like move, scale, rotate, and skew to SVG elements. ```python import svgutils.transform as sg # Load an SVG file fig = sg.fromfile("diagram.svg") element = fig.getroot() # Move and scale: moveto(x, y, scale_x=1, scale_y=None) element.moveto(100, 50, scale_x=0.75) # Rotate around a pivot point: rotate(angle, x=0, y=0) element.rotate(45, x=50, y=50) # 45 degrees around point (50, 50) # Skew along x and y axes element.skew(x=10, y=5) # Skew 10 degrees on x-axis, 5 on y-axis # Scale uniformly or non-uniformly element.scale(0.5) # Uniform scaling element.scale(x=0.8, y=1.2) # Non-uniform scaling # Find element by ID specific_element = element.find_id("my-circle") specific_element.moveto(200, 100) # Convert element to string svg_string = element.tostr() ``` -------------------------------- ### FigureElement - Transform SVG Elements Source: https://context7.com/btel/svg_utils/llms.txt The FigureElement class provides transformation methods for moving, scaling, rotating, and skewing SVG elements. ```APIDOC ## FigureElement - Transform SVG Elements ### Description The `FigureElement` class provides transformation methods for moving, scaling, rotating, and skewing SVG elements. ### Method ```python import svgutils.transform as sg # Load an SVG file fig = sg.fromfile("diagram.svg") element = fig.getroot() # Move and scale: moveto(x, y, scale_x=1, scale_y=None) element.moveto(100, 50, scale_x=0.75) # Rotate around a pivot point: rotate(angle, x=0, y=0) element.rotate(45, x=50, y=50) # 45 degrees around point (50, 50) # Skew along x and y axes element.skew(x=10, y=5) # Skew 10 degrees on x-axis, 5 on y-axis # Scale uniformly or non-uniformly element.scale(0.5) # Uniform scaling element.scale(x=0.8, y=1.2) # Non-uniform scaling # Find element by ID specific_element = element.find_id("my-circle") specific_element.moveto(200, 100) # Convert element to string svg_string = element.tostr() ``` ``` -------------------------------- ### Remove grid from SVG figure Source: https://context7.com/btel/svg_utils/llms.txt Finalize positioning by removing grid elements from a composed figure. ```python Figure("16cm", "10cm", SVG("plot.svg").move(100, 75) ).save("final_figure.svg") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.