Add an animation widget

The animation widget includes an animation status bar and controls to play or pause animated data. The filter property of your map's style, applied to either a date or numeric field, drives both the animation and the widget. Only one animation can be controlled per layer. To learn more about creating animations visit: Animated visualizations.

To see available parameters run help(animation_widget).

In the example below, collisions in Seattle are animated by the date they occured.


In [1]:
from cartoframes.auth import set_default_credentials
from cartoframes.viz import Layer, animation_widget, animation_style

set_default_credentials('cartoframes')

In [2]:
Layer(
    'seattle_collisions',
    style=animation_style('incdate', color='blue', duration=20),
    widgets=[
        animation_widget(
            title='Collision Date',
            description= 'Play, pause, or select the range of the animation'
        )]
)


Out[2]:
:
StackTrace
    ">

    Using dates in a DataFrame

    When animating data from a DataFrame, the columns that need to be treated as Dates should be datetime format

    
    
    In [3]:
    import pandas as pd
    import geopandas
    
    data = {
        'date_column': ['2019-11-10', '2019-11-11', '2019-11-12', '2019-11-13', '2019-11-14', '2019-11-15'],
        'lon': [50, 40, 30, 50, 30, 40],
        'lat': [0, 1, 2, 3, 2, 1]
    }
    
    df = pd.DataFrame(data)
    
    
    
    In [4]:
    df['date_column']= pd.to_datetime(df['date_column'])
    
    
    
    In [5]:
    gdf = geopandas.GeoDataFrame(df, geometry=geopandas.points_from_xy(df.lon, df.lat))
    
    Layer(
        gdf,
        style=animation_style('date_column', color='blue', size=20, duration=20),
        widgets=animation_widget(title='November')
    )
    
    
    
    
    Out[5]:
    :
    StackTrace
      ">