http://hplgit.github.io/web4sciapps/doc/pub/._part0013_web4sa_plain.htmlhplgit.github.io
SVG plots
Inline figures in HTML, instead of using files, are most often realized by XML code with the figure data in SVG format. Plot strings in the SVG format are created very similarly to the PNG example:
figfile = StringIO()
plt.savefig(figfile, format='svg')
figdata_svg = figfile.buf
The figdata_svg string contains XML code text can almost be directly embedded in HTML5. However, the beginning of the text contains information before the svg tag that we want to remove:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
/p>
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
The removal is done with a little string manipulation:
figdata_svg = '
Now, figdata_svg can be directly inserted in HTML code without any surrounding tags. The file compute.py in the vib4_flask application directory contains all the details.