我正在尝试使用背景图像为plotly/dash创建绘图。绘图已创建,但背景图像未创建。文件和映像位于同一目录中
我错过什么了吗
import base64
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objects as go
IMAGE_FILENAME1 = 'link.png'
image1 = base64.b64encode(open(IMAGE_FILENAME1, 'rb').read())
fig = go.Figure(
data=[go.Bar(y=[2, 1, 3])],
layout_title_text="Native Plotly rendering in Dash"
)
fig.update_layout( images= [dict(
#source="KU.png",
source='data:image/png;base64,{}'.format(image1.decode()),
#xref="container",
#yref="container",
layer="below")])
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Graph(id="graph", figure=fig),
])
app.run_server(debug=True)
获取图的属性:
fig
Figure({
'data': [{'type': 'bar', 'y': [2, 1, 3]}],
'layout': {'images': [{'layer': 'below',
'source': ('data:image/png;base64,iVBORw0K' ... 'Q7B0QA13afSQHVAAAAAElFTkSuQmCC')}],
'template': '...',
'title': {'text': 'Native Plotly rendering in Dash'}}
我的建议可能无法解决这个问题,因为不清楚图像不显示什么样的图形。我已尝试显示带有您代码的图像。 我唯一修改的代码是下面的一行
相关问题 更多 >
编程相关推荐