我正在运行 svg_filter_line (官方示例)在带有 Python3 的 MacOS 上的 Jupyter 中。
SVG 适用于大量 svg 图像(例如来自 wiki 的世界地图图像)
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'))
svgutils
可以安装如下:
conda install -c conda-forge svgutils
关于python - IPython.显示 : SVG cannot render a svg image generated by svg_filter_line (official example),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56514491/