我想把SVG图像嵌入到matplotlib子图中。
matplotlib只能本地读取PNG格式的图片,但如果安装了PIL,则会使用它来加载图像并返回一个数组(如果可能),该数组可与imshow()一起使用。 http://matplotlib.sourceforge.net/api/pyplot_api.html
import Image
filename = "/tmp/figure.svg"
pil_img = Image.open(filename) # PIL image
img = np.asarray(pil_img) # converting PIL image into numpy array
self.axes.cla()
self.axes.imshow(img)
但是PIL不支持SVG。报错信息如下:
“/usr/lib/python2.7/dist-packages/PIL/Image.py”,第1980行,打开文件时, 抛出异常:“无法识别图像文件”。 如何将SVG文件转换为栅格图以便使用imshow进行绘制?或者如何直接使用matplotlib绘制矢量图形?
谢谢。