我的主要目标是在气象图上显示天气图标,使用Dash中的绘图仪。该要求的示例如下所示:
为此,我尝试编写以下代码:
def graph_pictos(df: pd.DataFrame):
k = 0
fig = go.Figure()
file_path = 'pictos_png/'
for row in df.itertuples():
picto_number = str(round(row.pictonumber_3h))
image_filename = ''.join((file_path, picto_number,'_big.png'))
picto_image = base64.b64encode(open(image_filename, 'rb').read())
fig.add_layout_image(
go.layout.Image(
source = 'data:image/png;base64,{}'.format(picto_image.decode()),
xref = "x",
yref = "y",
x = k,
y = 1,
sizex = 0.5,
sizey = 0.5,
xanchor="center",
yanchor="middle"
)
)
k+=1
return fig
我使用一个图标图像文件夹(“pictos_png”),其中每个图像名称对应一个天气代码。然后,数据帧df
被传递给函数,其中每一行对应于所考虑的时间戳的天气代码。但是,此函数似乎只显示一个天气图标,对应于数据框df
中的最后一个图标代码,如图所示:
有人知道为什么这不能正常工作吗
您提供的代码不容易复制。不过,以下设置应该与您要查找的内容非常接近:
Plot
Code
相关问题 更多 >
编程相关推荐