如何解决读取 svg 文件以插入 matplotlib
我正在尝试从 SVG 文件中读取图像并插入到 matplotlib 图中。
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,'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()
我尝试使用 pylustrator
post 来读取 svg 图像。当输入图像为 png 格式时,该代码有效。但我无法添加保存在 svg 扩展名 (image) 中的相同图像。
由于以下错误,我无法成功插入,
"float".format(self._A.dtype))
TypeError: Image data of dtype object cannot be converted to float
有关如何解决此问题的建议将非常有用。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。