python - Python plotly 徽标从图表中消失
问题描述
我必须创建一个显示一个数据表并在顶角有两个徽标的简单报告。下面的代码在以前的项目中工作,但现在我在新计算机上将它重用于新项目,它不会显示徽标。
我没有收到错误消息。相同版本的 plotly 和 python "plotly==4.6.0" "Python 3.6.1"
请注意,唯一改变的是数据表中显示的数据。
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()
解决方案
我认为问题出source
在您的layout
. 我已将您的代码与此图像 URL而不是相对路径一起使用,它运行良好,这是一个屏幕截图,知道我使用了一个简单的表格作为我的df
:
在我看来,你有两种选择来克服这个问题:
将这些图像上传到云服务并使用它们的 URL。
或者根据这个Plolty community thread,您可以使用
Pillow.Image
类从本地机器读取图像。您可以通过运行pip install pillow
和修改代码来轻松安装它,如下所示:from PIL import Image layout= go.Layout(images= [dict( source= Image.open('assets\\MiniLogo.png'), ...)])
推荐阅读
- python - 如何在不刷新页面的情况下使用提交表单按钮?
- javascript - Node.JS - 为什么等待不等待
- google-apps-script - 选择状态时将 2 列数据移动到不同的选项卡
- python - 如何每次将变量保存到文本文件到新行?
- firebase - 如何在提供者登录时在 Firebase Auth 中定义 UID
- react-native - 需要帮助在 React Native 项目中实现 RNCamera
- python - 为什么 ImageStat 返回有符号整数图像的错误统计信息(`mode='I'`)?
- azure-powershell - 我需要编写一个充当“看门狗”的 Powershell 脚本
- python - Python键盘库不抑制Linux上的击键
- tfrecord - 将变量传递给 GEE 导出函数