简体   繁体   English

Python plotly 徽标从图表中消失

[英]Python plotly logo disapering from chart

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"相同版本的 plotly 和 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()

I think the problem is within the source argument in your layout .我认为问题出在您的layout中的source参数中。 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 :我已将您的代码与 此图像 URL一起使用,而不是相对路径,它运行良好,这是一个屏幕截图,知道我使用了一个简单的表格作为我的df

在此处输入图像描述

In my opinion, you have two options to overcome that:在我看来,你有两种选择来克服这个问题:

  • Upload these images to a cloud-service and use their URLs instead.将这些图像上传到云服务并使用它们的 URL。

  • Or according to this Plolty community thread , you can use Pillow.Image class to read the image from your local machine.或者根据这个Plolty community thread ,您可以使用Pillow.Image class 从本地机器读取图像。 You can install it easily by running pip install pillow and modify your code to be like so:您可以通过运行pip install pillow轻松安装它并修改您的代码如下:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM