Getting data values from Animated plot

I have plotted animated race line chart using graphing object in dash. When I click start button the race line chart starts. I want that if I click another button say “Show” then it should print the current data values of race line chart. How should I get the values?

x_axis = list(range(df.shape[0]))
y_axis = list(df['4. close'])
frames = []
for frame in range(1, len(x_axis)+1):

    x_frame = np.arange(frame)
    y_frame = list(df.iloc[:frame-1, 4])
    #y_frame = [y_frame]
    curr_frame = go.Frame(data = [go.Scatter(x = x_frame, y = y_frame, mode = 'lines')])

title1 = "Stock Simulation of " + str(list(comp_name)[0])
figure = go.Figure(data=[go.Scatter(x = np.array([1]), y = np.array([60.10]), mode='lines')],
                                           "pad":{'l':80, "t":200},
                                              "args":[None, {"frame": {"duration":10,
                                                             "fromcurrent": True,
                                                             "transition": {"duration":0}
                           "xaxis":{"range":[0, df.shape[0]]},
                           "yaxis":{"range":[0, max(y_axis)]}

dash_app = dash.Dash(server=flask_app, name="Dashbar", url_base_pathname="/dash/")
    dash_app.layout = html.Div(
            #html.Div(children="""  """),
            dcc.Graph(id="example-graph", figure=figure),
            dbc.Button('Show', id='example-button', color='primary',
                       style={'margin-bottom': '1em', 'margin-left': '46%'}),


        Output('para', 'children'),
        Input('example-button', 'n_clicks')
    def show_data(n_clicks):
        if n_clicks is None:
            raise PreventUpdate
            return "What to add here?"

Not sure if this will help but if you want to get data from the graph you can refer to this it shows how to access the value of data points by events such as hovering or clicking them.

Thanks @atharvakatre, I think it might be helpful, do you know how to apply that on animation graph?

It doesn’t matter if the graph is animated or not.

I have made this minimal example with an animated plot.
Check this out:

import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output
import as px

df =
animations = {
    'Scatter': px.scatter(
        df, x="gdpPercap", y="lifeExp", animation_frame="year",
        animation_group="country", size="pop", color="continent",
        hover_name="country", log_x=True, size_max=55,
        range_x=[100,100000], range_y=[25,90]),
        df, x="continent", y="pop", color="continent",
        animation_frame="year", animation_group="country",

app = dash.Dash(__name__)

app.layout = dbc.Container([
    html.P("Select an animation:"),
        options=[{'label': x, 'value': x} for x in animations],

    Output("graph", "figure"),
    [Input("selection", "value")])
def display_animated_graph(s):
    return animations[s]

    Output("info", "children"),
    [Input("graph", "clickData"),
     Input('graph', 'hoverData')])
def display_animated_graph(clickdata, hoverdata):
    x1 = y1 = x2 = y2 = 'None'
    if clickdata is not None:
        x1 = clickdata['points'][0]['x']
        y1 = clickdata['points'][0]['y']
    if hoverdata is not None:
        x2 = hoverdata['points'][0]['x']
        y2 = hoverdata['points'][0]['y']
    content = dbc.Row([
                html.H3('Clicked Data'),
                html.H5('x : ' + str(x1)),
                html.H5('y : ' + str(y1)),
                html.H3('Hover Data'),
                html.H5('x : ' + str(x2)),
                html.H5('y : ' + str(y2)),
    return content

1 Like

I will look into it…Thank you @atharvakatre

1 Like