Adding an annotation to a scatter_geo object

Hi here,
I have the following country lat and lon info that I use to display a fig.scatter_geo()
I would like to add afew arrows between countries. However I get a ValueError received for the ‘axref’ property of layout.annotation Received value: ‘lon’.
If I change the axref, ayref, xref, yref to ‘x’, ‘y’ The arrow appears but on a XY coordinate and not on the lon, lat geo map coordinates.

Below a very simple example of what I am trying to do.

Many thanks

data = {
    'Country Code': ['at', 'be', 'ch', 'cz', 'de', 'dk', 'dk1', 'dk2', 'fr', 'nl', 'no2', 'pl', 'se', 'se4'],
    'Country Name': ['Austria', 'Belgium', 'Switzerland', 'Czech Republic', 'Germany', 'Denmark', 'Denmark (Zone DK1)', 'Denmark (Zone DK2)', 'France', 'Netherlands', 'Norway (Zone NO2)', 'Poland', 'Sweden', 'Sweden (Zone SE4)'],
    'Latitude': [47.5162, 50.8503, 46.8182, 49.8175, 51.1657, 56.2639, 55.6761, 55.6761, 46.6034, 52.3676, 60.4720, 51.9194, 60.1282, 58.1282],
    'Longitude': [14.5501, 4.3517, 8.2275, 15.4730, 10.4515, 9.5018, 12.5683, 12.5683, 1.8883, 4.9041, 5.4689, 19.1451, 18.6435, 14.6435]
cc = pd.DataFrame(data)
fig = px.scatter_geo(cc, 
                     text='Country Name',
                     hover_name='Country Name',
                     hover_data=['Country Code'],

# Adding a manual Line between FR -> DE   FR_X_lon, FR_Y_lat   DE_X_lon DE_Y_lat
fig.add_annotation({'ax': 1.8883, 'ay': 46.6034, 'axref': 'lon', 'ayref': 'lat', 'x': 10.4515, 'y':51.1657, 'xref': 'lon', 'yref': 'lat', 'showarrow': True, 'arrowhead': 1})

Arrows cannot be drawn, but the following code can be used to just draw a line.

fig.add_trace(go.Scattergeo(locationmode='country names',
                            lon=[1.8883, 10.4515],
                            lat=[46.6034, 51.1657],
                            line=dict(width=1, color='red')))

Thanks to your quick response. I need a directed line. To show direction.

@empet any work arround?

@bixin Plotly arrow in scattergeo with text on the line - #2 by empet

1 Like

Amazing thank you so much.
Do you know if is possible to add a date range slider to display the geo map points and arrows for specific dates?

@bixin Yes, it is possible, with a slider.

1 Like

@empet maybe you have a demo code for adding that datetime slider in a map figure similar to mine? Many thanks :pray:

I’m on holiday now, but please search within jupyter notebooks posted at: