Mapbox animation [Scattermapbox, Frames, Text]

Hi!

I am trying to use plotly + mapbox to make an animation.

The idea is to have scatter markers on a map, changing from frame to frame.
Each frame represents a datetime, that would be displayed on top of the graph.

I am using go.Scattermapbox with mode set to "text " to write the datetime.

So far I have run into two problems:

textposition on go.Scattermapbox doesnt seem to work properly.
I had to hard set the coordinates of the text with lat & lon.
Which results in issues if we are to zoom in/out during animation.

Every frame change works fine for the scattermapbox marker animation, but the scattermapbox datetime text flickers through frame changes.

How to prevent that?

Thank you!
E Pattaro

Hi @epattaro,

If you’d like the date text to be positioned in a stationary location on the figure (not by lat/lon), that I’d recommend using an annotation in paper coordinates. See https://plot.ly/python/text-and-annotations/#adding-annotations-with-xref-and-yref-as-paper. If you want to annotation at the top-middle of the figure, you’d use something like:

layout = go.Layout(
    annotations=[
        dict(
            x=0.5,
            y=1.0,
            showarrow=False,
            text='Custom annotation text',
            xref='paper',
            yref='paper'
        ),
    ]
)

Hope that helps,
-Jon

I used the layout.annotation and it solved both issues. (the flickering on frame animation as well)

thx!

1 Like