Skip to main content

svg2mpl

Render SVG files into matplotlib artists.

svg2mpl parses an SVG into matplotlib Path/Patch objects and draws them on an Axes. Unlike a one-off "extract the paths" helper, it aims to be faithful to the SVG: it honors element transforms, <g> group inheritance, viewBox, the basic shape elements, and CSS styling.

📖 Documentation — guide, runnable example notebooks with rendered plots, and the full API reference.

Install

pip install svg2mpl
# with <style>-block CSS support:
pip install "svg2mpl[css]"

Quick start

import matplotlib.pyplot as plt
import svg2mpl

fig, ax = plt.subplots()
svg2mpl.add_svg("drawing.svg", ax=ax)
ax.set_aspect("equal")
plt.show()

add_svg can also place a drawing at a position/size/rotation, exclude paths by id, recolor per id, or convert to grayscale:

svg2mpl.add_svg(
    "logo.svg",
    xy=(2, 3),          # data coordinates of the anchor
    width=1.5,          # final width (height kept to aspect ratio)
    origin=(0.5, 0.5),  # anchor at the drawing's center
    rotation=30,
    exclude=r"grid.*",  # skip paths whose id matches
)

To inspect the parsed scene without drawing:

scene = svg2mpl.load("drawing.svg")
for shape in scene.shapes:
    print(shape.id, shape.kwargs)

Coverage

Area Supported
Shapes path, rect (incl. rounded), circle, ellipse, line, polyline, polygon
Structure <g> groups & inheritance, <use>/<defs>/<symbol>, viewBox
Transforms matrix, translate, scale, rotate, skewX, skewY
Styling presentation attributes, inline style, <style> CSS (with [css] extra)
Paint named/hex/rgb()/rgba()/hsl() colors, currentColor, per-paint opacity

Gradients and <text> have best-effort support; see the docstrings for the current limitations (matplotlib has no native gradient fill, and font matching is approximate).

Coordinate system

SVG's y axis points down; matplotlib's points up. By default add_svg flips the y axis so a drawing looks the same as in a browser. Pass flip_y=False to keep raw SVG coordinates.

License

MIT

Metadata

Release files for svg2mpl 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for svg2mpl 0.1.0
File Size Uploaded Provenance Actions
svg2mpl-0.1.0.tar.gz 54.3 kB Without provenance Details for svg2mpl-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for svg2mpl 0.1.0
File Interpreter ABI Platform Actions
svg2mpl-0.1.0-py3-none-any.whl Python 3 none any Details for svg2mpl-0.1.0-py3-none-any.whl

Total release size: 81.2 kB

Release files / svg2mpl-0.1.0.tar.gz

Download URL svg2mpl-0.1.0.tar.gz
Size 54.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ab011e58c4e60c68238007faad19aeefb3b9592735f7f15b0171e2d43a7a4675
BLAKE2b-256 checksum
How to use checksums
ece5efde6413b167ac7ac1689abd55632e46adf28e8c0cc78115a8d6dd33a987
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / svg2mpl-0.1.0-py3-none-any.whl

Download URL svg2mpl-0.1.0-py3-none-any.whl
Size 26.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da9d4c42aabe70b91c0b14e3ba68bd9be5d40113db1e8ce6336cb0ed833c2990
BLAKE2b-256 checksum
How to use checksums
b3d2b37bdba9529b811c6d3ba4938d26a8bb1af7c744b13394c6b25cb9b6a85e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for svg2mpl 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page