Insert SVGs into matplotlib figures
Project description
skunk ![](https://pypi-camo.freetls.fastly.net/ae1368fabb22e1382b0ece892caa6aa321200bea/68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f776869746561642f736b756e6b2f6d61696e2f74657374732f736b756e6b2e737667)
Insert SVGs into matplotlib
pip install skunk
Overwrite Subplot
import skunk
import numpy as np
import os
import matplotlib.pyplot as plt
fig, axs = plt.subplots(ncols=2, squeeze=True)
x = np.linspace(0, 2 * np.pi)
axs[0].plot(x, np.sin(x))
# important line where we set ID
skunk.connect(axs[1], 'sk')
plt.tight_layout()
# Overwrite using file path to my svg
# Can also use string
svg = skunk.insert(
{
'sk': 'skunk.svg'
})
with open('replaced.svg', 'w') as f:
f.write(svg)
Output
SVG in Annotation
Read about annotation boxes first
import numpy as np
fig, ax = plt.subplots(figsize=(300/72, 300/72))
x = np.linspace(0, 2 * np.pi)
ax.plot(x, np.sin(x))
# new code: using skunk box with id sk1
box = skunk.Box(50, 50, 'sk1')
ab = AnnotationBbox(box, (np.pi / 2, 1),
xybox=(-5, -100),
xycoords='data',
boxcoords="offset points",
arrowprops=dict(arrowstyle="->"))
ax.add_artist(ab)
# sknunk box with id sk2
box = skunk.Box(50, 50, 'sk2')
ab = AnnotationBbox(box, (3 * np.pi / 2, -1),
xybox=(-5, 100),
xycoords='data',
boxcoords="offset points",
arrowprops=dict(arrowstyle="->"))
ax.add_artist(ab)
# insert current figure into itself at sk1
# insert svg file in sk2
svg = skunk.insert(
{
'sk1': skunk.pltsvg(),
'sk2': 'skunk.svg'
})
with open('replaced2.svg', 'w') as f:
f.write(svg)
Output
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
skunk-0.1.0.tar.gz
(4.1 kB
view hashes)
Built Distribution
skunk-0.1.0-py3-none-any.whl
(4.4 kB
view hashes)