dash plolty不在图上显示图像

tvokkenx  于 2021-09-08  发布在  Java
关注(0)|答案(1)|浏览(448)

我试着把我的数字图像,像一个水印,我下面的文档。它与“vox”示例一起工作。但是,当我尝试将本Map像放到图形中时,它们不会显示。
这是我的密码:

import plotly.express as px
import requests
import pandas as pd 

response = requests.get("https://api.covalenthq.com/v1/1/address/0x343A53A1E8b17beDd15F47a28195Bc8C120d4443/portfolio_v2/?format=format%3Dcsv&key=ckey_57eeb470248541708eeaf028c9d").json()['items']
data=pd.json_normalize(response,record_path=['holdings'],meta=['contract_ticker_symbol','contract_name',"contract_address"])
data['timestamp']=pd.to_datetime(data['timestamp']).dt.strftime('%D')

# colors = {

  #  'background': 'black', #Sets plot background color black
   # 'text': '#FFFFFF' #Sets plot text color white

# }

fig = px.line(data, x="timestamp", y="close.quote", color="contract_name",color_discrete_sequence=["#ff4c8b", "#00d8d5",'#f7f7f7'], line_group="contract_ticker_symbol",labels={    #Changes colum names
                    "contract_name":'Contract Name', 
                     "timestamp": "Date",
                     "close.quote": "USD Value",
                     "contract_ticker_symbol": "Ticker"
                 }, title='Asset Value Over Time', hover_name="contract_ticker_symbol")

fig.add_layout_image(
    dict(
        source="vox.png",
        xref="paper", yref="paper",
        x=0.5, y=0.24,
        sizex=0.5, sizey=0.6,
        xanchor="center", yanchor="bottom"
    )
)

fig.add_layout_image(
            dict(
                source="aa_footer.svg",
                xref="paper", yref="paper",
                x=0.7, y=(-0.20),
                sizex=1.7, sizey=.8,
                xanchor="center", yanchor="bottom"
            )
        )
fig.update_layout(plot_bgcolor='black', paper_bgcolor='black',font_color='#FFFFFF')

# update layout properties

fig.update_layout(
    margin=dict(r=20, l=300, b=75, t=125),
    title=("Asset Valuation Overtime<br>" +
           "<i>Assets in Ethereum Blockchain</i>"),
)
fig.update_xaxes(showgrid=False) #hide vertical gridlines

fig.show()

我试着将我的图片放入“资产”文件夹和外部,并将它们上传到imgbb。仍然没有回应
这是我得到的数字:
[![在此处输入图像说明][2][2]
谁能告诉我怎么解决这个问题吗

baubqpgj

baubqpgj1#

最简单的方法是指定使用枕头库作为源获得的数据。官方参考说明可在此处找到。

from PIL import Image # new import

img = Image.open('./data/vox.png') # image path

# defined to source

fig.add_layout_image(
    dict(
        source=img,
        xref="paper", yref="paper",
        x=0.5, y=0.24,
        sizex=0.5, sizey=0.6,
        xanchor="center",
        yanchor="bottom",
        opacity=0.5
    )
)

相关问题