我從這里運(yùn)行了這個(gè)在 folium 地圖上顯示圖像的 folium 示例。我在我的 spyder 上運(yùn)行了這個(gè)程序,雖然它在 jupyter 上運(yùn)行良好import numpy as npimport pandas as pdimport numpy.ma as maimport foliumdef make_data(): x = np.linspace(-np.pi, np.pi, 101) sin = np.sin(x) cos = np.cos(x) cos[20:50] = np.NaN return pd.DataFrame(np.asanyarray([sin, cos]).T, columns=['sin', 'cos'], index=x)df = make_data()resolution, width, height = 75, 7, 3station = '42'lon, lat = -42, -21m = folium.Map(location=[lat, lon], zoom_start=5)import base64import matplotlib.pyplot as pltfig, ax = plt.subplots(figsize=(width, height))ax = df.plot(ax=ax, legend=False)ax.set_ylabel('Sea surface height (m)')png = 'mpld3_{}.png'.format(station)fig.savefig(png, dpi=resolution)encoded = base64.b64encode(open(png, 'rb').read())from folium import IFramehtml = '<img src="data:image/png;base64,{}">'.formatiframe = IFrame(html(encoded), width=(width*resolution)+20, height=(height*resolution)+20)popup = folium.Popup(iframe, max_width=2650)icon = folium.Icon(color="red", icon="ok")marker = folium.Marker(location=[lat-2, lon-1], popup=popup, icon=icon)marker.add_to(m)m.save('test.html')預(yù)期結(jié)果我的輸出
PNG圖像未顯示在Folium地圖上
拉丁的傳說(shuō)
2022-06-14 15:05:13