How to automatically adjust the position of a layout image using plotly?

89 Views Asked by At

I am trying to add a logo to a plotly figure that I then save as a html file.

I adjusted the x and y coordinates to display the logo in the top left corner of my html page.

enter image description here

However, when I open the same html file from a computer whose screen has a higher resolution, the logo is cropped:

enter image description here

Here is a MRE:

from PIL import Image
import plotly.graph_objects as go

def create_report():
    WeylandLogo = Image.open("Weyland.jpg")
    fig = go.Figure()
    fig.add_layout_image(
    dict(
        source=WeylandLogo,
        xref="paper", yref="paper",
        x=0, y=1.05,
        sizex=0.2, sizey=0.2,
        xanchor="left", yanchor="bottom"
        )
    )
    fig.write_html("cornbread.html")

create_report()

According to plotly's website, setting xref and yref to paper allows to use "normalized" coordinates.

If set to "paper", the x position refers to the distance from the left of the plotting area in normalized coordinates where "0" ("1") corresponds to the left (right).

I thought that this would automatically adjust the position of the logo, but apparently this is not the case. What parameters should I use?

0

There are 0 best solutions below