我正在Jupyter notebook中使用plotly创建一个电台地图。我的目标是能够将其导出为html文件,然后嵌入到网站上。下面的例子(绘制点,保存.html文件)和我目前所做的很相似。
我想为每一个点嵌入超链接,无论是在悬停文本中还是在点本身上,当图形保存为html文件时,这些链接将持续存在。可以做到吗?
import plotly.graph_objects as go
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_us_airport_traffic.csv')
df['text'] = df['airport'] + '' + df['city'] + ', ' + df['state'] + '' + 'Arrivals: ' + df['cnt'].astype(str)
fig = go.Figure(data=go.Scattergeo(
lon = df['long'],
lat = df['lat'],
text = df['text'],
mode = 'markers',
marker_color = df['cnt'],
))
fig.update_layout(
title = 'Most trafficked US airports<br>(Hover for airport names)',
geo_scope='usa',
)
fig.show()
plotly.offline.plot(fig, filename='examplemap.html')
取得了一些进展...
添加 import plotly.graph_objects as go
到前言,然后添加。
fig.add_trace(go.Scattergeo(
lat=[40.678306],
lon=[-105.040889],
marker={
"color": ["Crimson"],
"line": {
"width": 1
},
"size": 10
},
mode="markers+text",
name="",
text=[ "<a href=\"https://www.nist.gov/pml/time-and-frequency-division/radio-stations/wwv/\">WWV</a>"],
textfont={
"color": ["Crimson"],
"family": ["Droid Sans, sans-serif"],
"size": [22]
},
textposition=["top center"]
))
还得把这个整合到for循环中去 但它确实能生成链接并有效地输出到HTML中去