Python plotly logo disapering from chart

Viewed 74

I have to create a simple report that show one data table and have two logos in the top corners. The code below worked in a previous project but now that I’m reusing it on a new computer for a new project it wont show the logos.

I get no error message. Same version of plotly and python "plotly==4.6.0" "Python 3.6.1"

Please note that the only thing that changed is the data shown in the datatable.

import plotly.graph_objects as go
import pandas as pd



traces = go.Table(
    header=dict(values=list(df.columns),
            align='left'),
    cells=dict(
        values=df.T.values.tolist(),
        align='left'))



layout = go.Layout(
                title='Report <br>  {}'.format( report_date),
                title_x=0.5,
                paper_bgcolor='#FFFFFF',
                margin = {'t':100, 'b':40, 'r':40, 'l':40}
                ,images=[
                    dict(
                        source='assets\\MiniLogo.png',
                        xref='paper',yref='paper',
                        x=1,y=1.05,
                        sizex=0.2, sizey=0.2,
                        xanchor="right", yanchor="bottom"), 
                    dict(
                        source='assets\\Titlelogo.png',
                        xref='paper',yref='paper',
                        x=0,y=1.05,
                        sizex=0.2, sizey=0.2,
                        xanchor="left", yanchor="bottom")

                    ]

                )
fig = go.Figure(
        data=traces
        ,layout=layout)
fig.show()
1 Answers

I think the problem is within the source argument in your layout. I've used your code with this image URL instead of a relative path and it works perfectly and here is a screenshot knowing that I've used a simple table as my df:

enter image description here

In my opinion, you have two options to overcome that:

  • Upload these images to a cloud-service and use their URLs instead.

  • Or according to this Plolty community thread, you can use Pillow.Image class to read the image from your local machine. You can install it easily by running pip install pillow and modify your code to be like so:

    from PIL import Image
    
    layout= go.Layout(images= [dict(
                      source= Image.open('assets\\MiniLogo.png'),
                      ...)])
    
Related