有没有办法在带有 Scattergeo 的两个 lon, lat 对之间的一条线上有一个悬停文本

Is there a way to have a hovertext on a line between two lon, lat pairs with Scattergeo

我正在绘制航线图,希望在起点和终点之间的线上显示一个悬停文本。例如连接 JFK 和 SFO 的曲线应该在显示“JFK-SFO/38 flights”

的行显示悬停文本

我根据 plotly 图库中的示例添加了悬停文本。可以找到参考页 here。不幸的是,出于某种原因,将悬停文本的位置设置到行的中心并不起作用。如果将鼠标移动到机场起点一侧,文本将以所需格式显示。

import plotly.graph_objects as go
import pandas as pd

df_flight_paths = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_aa_flight_paths.csv')
df_flight_paths.head()

start_lat   start_lon   end_lat     end_lon     airline     airport1    airport2    cnt
0   32.895951   -97.037200  35.040222   -106.609194     AA  DFW     ABQ     444
1   41.979595   -87.904464  30.194533   -97.669872  AA  ORD     AUS     166
2   32.895951   -97.037200  41.938874   -72.683228  AA  DFW     BDL     162
3   18.439417   -66.001833  41.938874   -72.683228  AA  SJU     BDL     56
4   32.895951   -97.037200  33.562943   -86.753550  AA  DFW     BHM     168

fig = go.Figure()
flight_paths = []
for i in range(len(df_flight_paths)):
    fig.add_trace(
        go.Scattergeo(
            locationmode = 'USA-states',
            lon = [df_flight_paths['start_lon'][i], df_flight_paths['end_lon'][i]],
            lat = [df_flight_paths['start_lat'][i], df_flight_paths['end_lat'][i]],
            mode = 'lines',
            line = dict(width = 1,color = 'red'),
            hoverinfo='text',
            text=df_flight_paths.loc[i,'airport1'] + '-' + df_flight_paths.loc[i,'airport2'] +'/' + str(df_flight_paths.loc[i,'cnt']) + 'flights',
            textposition='top center',
            opacity = float(df_flight_paths['cnt'][i]) / float(df_flight_paths['cnt'].max()),
        )
    )

    
fig.update_layout(
    title_text = 'Feb. 2011 American Airline flight paths<br>(Hover for airport names)',
    showlegend = False,
    width=1000,
    height=800,
    geo = dict(
        scope = 'north america',
        projection_type = 'azimuthal equal area',
        showland = True,
        landcolor = 'rgb(243, 243, 243)',
        countrycolor = 'rgb(204, 204, 204)',
    ),
)
fig.show()