I am running svg_filter_line (official example) in Jupyter on MacOS with Python3.
SVG works well with lots of svg image (Worldmap image from wiki, for instance)
the original coding of svg_filter_line works well too.
running svg_filter_line generates a svg image named 'svg_filter_line.svg'.
SVG cannot render this svg image 'svg_filter_line.svg', no error, no warning.
It was slightly hard to get to this. Here is the solution: While working with the files: I found that the type of file displayed by display()
or display_svg()
function is slightly different from each other (Difference is mainly in the namespace). As a workaround, had to re-save the SVG file using svgutils, follow by reading and displaying as below:
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
can be installed as below:
conda install -c conda-forge svgutils
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With