import cairosvg
from IPython.display import SVG, Image, HTML
def show(text_content, text_attributes=""):
svg = f"""
<svg width="500" height="80" xmlns="http://www.w3.org/2000/svg">
<rect x="0" y="0" width="500" height="80" fill="lightgrey"/>
<circle cx="250" cy="40" r="5" fill="green"/>
<text x="250" y="40" font-size="32px" {text_attributes}>{text_content}</text>
</svg>
""".format()
print("cairosvg.svg2png(...)")
cairosvg.svg2png(svg, write_to='test.png')
display(Image("test.png"))
print("IPython.display(SVG(...))")
display(SVG(svg))
show(
text_content = """<tspan>1.000·</tspan><tspan>10</tspan><tspan dy="-0.6em" font-size="0.6em">-12</tspan>""",
text_attributes='text-anchor="middle"'
)
cairosvg.svg2png(...)
IPython.display(SVG(...))
show(
text_content = """<tspan>one</tspan><tspan>TWO</tspan><tspan>three</tspan>""",
text_attributes='text-anchor="middle"'
)
cairosvg.svg2png(...)
IPython.display(SVG(...))
show(
text_content="""<tspan>oneTWOthree</tspan>""",
text_attributes='text-anchor="middle"'
)
cairosvg.svg2png(...)
IPython.display(SVG(...))