简体   繁体   English

如何从 matplotlib 中创建包含元数据的压缩可缩放矢量图形

[英]how to create compressed scalable vector graphics including metadata from within matplotlib

  • matplotlib allows generation of svgz files, compression rate mor than 90% matplotlib 允许生成 svgz 文件,压缩率超过 90%
  • external compression of svg files with gzip -9 worse to extremely worse使用 gzip -9 对 svg 文件进行外部压缩更糟甚至更糟
  • xml.etree.ElementTree allows definition of metadata to svg dataset, but export apparently only to svg, not svgz. xml.etree.ElementTree 允许将元数据定义为 svg 数据集,但显然仅导出到 svg,而不是 svgz。

Is there a way in python to add metadata to the xml tree and export it to svgz at the compression rate achieved by matplotlib.pyplot.savefig(..., format='svgz') ? python中有没有办法将元数据添加到xml树并以matplotlib.pyplot.savefig(..., format='svgz')实现的压缩率将其导出到svgz?

Maybe you would like to do this也许你想这样做

import io
from matplotlib.figure import Figure
from matplotlib.backends.backend_svg import FigureCanvasSVG

fig = Figure()
# do your fig stuffs

output = io.BytesIO()
FigureCanvasSVG(fig).print_svg(output)

Now, the SGV can be extracted as fol:现在,SGV 可以提取如下:

output.getvalue()

If you are looking for SGVZ (gzip compressed) try:如果您正在寻找 SGVZ(gzip 压缩),请尝试:

FigureCanvasSVG(fig).print_svgz(output)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM