I'm trying to visualize an image on a plotly plot using px.imshow(). Is it possible to pass in a svg for this rather than an image array?
Thanks in advance.
I'm trying to visualize an image on a plotly plot using px.imshow(). Is it possible to pass in a svg for this rather than an image array?
Thanks in advance.
 
    
    px.imshow().  Have used cairosvg (this library was somewhat challenging to install)import numpy as np
import requests, io
import PIL
import cairosvg
import plotly.express as px
import plotly.graph_objects as go
svg_url = "https://logincdn.msauth.net/16.000.28611.4/content/images/microsoft_logo_ee5c8d9fb6248c938fd0dc19370e90bd.svg"
res = requests.get(svg_url)
svgs = [
    '<svg width="100" height="100"><circle cx="20" cy="20" r="10" stroke="black" stroke-width="4" fill="red" /></svg>',
    '<svg width="100" height="100"><circle cx="40" cy="40" r="20" stroke="black" stroke-width="4" fill="red" /></svg>',
    '<svg width="100" height="100"><circle cx="60" cy="60" r="30" stroke="black" stroke-width="4" fill="red" /></svg>',
]
im = [
    PIL.Image.open(io.BytesIO(cairosvg.svg2png(bytestring=svg))).convert("RGBA")
    for svg in svgs
]
go.Figure(data=px.imshow(im[0]).data,
    frames=[go.Frame(data=px.imshow(im).data) for im in im]).update_layout(
    updatemenus=[
        dict(
            type="buttons", buttons=[dict(label="Play", method="animate", args=[None])]
        )
    ]
)
