I am trying to read an image from an SVG file and insert in matplotlib figure.
import matplotlib.pyplot as plt
import pylustrator as pyl
import numpy as np
from matplotlib.figure import Figure
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
from svglib.svglib import svg2rlg
ax = plt.subplot(111)
ax.plot(
[1, 2, 3], [1, 2, 3],
'go-',
label='line 1',
linewidth=2
)
# arr_img = plt.imread("stinkbug.svg")
# arr_img = svg2rlg("stinkbug.svg")
arr_img = pyl.load("stinkbug.svg")
im = OffsetImage(arr_img)
ab = AnnotationBbox(im, (1, 0), xycoords='axes fraction')
ax.add_artist(ab)
plt.show()
I tried to use pylustrator
post for reading the svg image. The code works when the input image is in png format. But I am not able to add the same image saved in svg extension(image).
I couldn't successfully insert due to the following error,
"float".format(self._A.dtype))
TypeError: Image data of dtype object cannot be converted to float
Suggestions on how to fix this will be really helpful.