plot SVG within matplotlib figure (embedded in wxP

2019-05-05 09:12发布

I am trying to embed a SVG image within a matplotlib subplot.

matplotlib can only read PNGs natively, but if PIL is installed, it will use it to load the image and return an array (if possible) which can be used with 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)

But of course PIL does not support SVG. The error:

File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1980, in open

raise IOError("cannot identify image file")

IOError: cannot identify image file

How can I rasterize the SVG file to plot using imshow or directly plot the vectors using matplotlib?

Thanks.

0条回答
登录 后发表回答