Render SVG files into matplotlib artists.
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file svg2mpl-0.1.0.tar.gz.
File metadata
- Download URL: svg2mpl-0.1.0.tar.gz
- Upload date:
- Size: 54.3 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab011e58c4e60c68238007faad19aeefb3b9592735f7f15b0171e2d43a7a4675
|
|
| MD5 |
9ce1adfc0e82400f17a1742d8cdf284e
|
|
| BLAKE2b-256 |
ece5efde6413b167ac7ac1689abd55632e46adf28e8c0cc78115a8d6dd33a987
|
File details
Details for the file svg2mpl-0.1.0-py3-none-any.whl.
File metadata
- Download URL: svg2mpl-0.1.0-py3-none-any.whl
- Upload date:
- Size: 26.9 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da9d4c42aabe70b91c0b14e3ba68bd9be5d40113db1e8ce6336cb0ed833c2990
|
|
| MD5 |
60f741e4f818ced3f0e38ca4337dddf9
|
|
| BLAKE2b-256 |
b3d2b37bdba9529b811c6d3ba4938d26a8bb1af7c744b13394c6b25cb9b6a85e
|