Jay*_*Jay 5 python svg matplotlib jupyter-notebook
我在使用Python3的 MacOS上的Jupyter中运行svg_filter_line(官方示例)。
SVG与很多svg图像(例如,来自Wiki的Worldmap图像)一起使用时效果很好
svg_filter_line的原始编码也很好。
运行svg_filter_line会生成一个名为“ svg_filter_line.svg”的svg映像。
SVG无法呈现此svg图像'svg_filter_line.svg',没有错误,没有警告。
做到这一点有点困难。这是解决方案: 在处理文件时:我发现display()或display_svg()函数显示的文件类型彼此略有不同(差异主要在于命名空间)。作为解决方法,必须使用 svgutils 重新保存 SVG 文件,然后读取并显示如下:
import svgutils.transform as sg
from IPython.display import SVG,display
#create new SVG figure
fig = sg.SVGFigure("16cm", "10cm")
# load matpotlib-generated figures
fig1 = sg.fromfile('svg_filter_line.svg')
plot1 = fig1.getroot()
fig.append([plot1])
fig.save("svg_filter_line2.svg")
display(SVG(filename='svg_filter_line2.svg'))
Run Code Online (Sandbox Code Playgroud)
svgutils可以按如下方式安装:
conda install -c conda-forge svgutils