python - Matplotlib svg as string and not a file -
Get link
Facebook
X
Pinterest
Email
Other Apps
I want to use Matplotlib and pyplot to generate a svg image used in the Django framework. As of now, I am creating image files that are linked to the page, but is there a way to meet STVG image directly as Unicode string without writing the file system?
StringIO to avoid writing any file-object on disk Try to use import matplotlib.pyplot as plt import matlotlib with string IO np x = np.arange (0, np.pi * 3, .1) y = np.sin (x) fig = Import as plt.figure () plt. Plot (x, y) imgdata = StringIO.StringIO () fig.savefig (imgdata, format = 'svg') imgdata.seek (0) # Open the data again svg_dta = imgdata.buf # This is svg data file (' Test.htm ',' w '). Write (svg_dta) # this test
Comments
Post a Comment