0

I am new to Dash and trying to run the below code for a Scatter plot.The graph is coming but no data points in it.May I know where I went wrong

My Code

import numpy as np
import dash
import dash_html_components as html
import plotly.graph_objects as go
import dash_core_components as dcc

app = dash.Dash()

np.random.seed(42)

random_x = np.random.randint(1, 101, 100)
random_y = np.random.randint(1, 101, 100)

app.layout = html.Div(
    [
        dcc.Graph(
            id="Scatter Plot",
            figure={
                "Data": [
                    go.Scatter(
                        x=random_x,
                        y=random_y,
                        mode="markers",
                    )
                ],
                "layout": go.Layout(title="My Scatter Plot"),
            },
        )
    ]
)

if __name__ == "__main__":
    app.run_server()

My Output

enter image description here

3
  • maybe delete the empty line before mode='markers', ? or was that a copy & paste error? Commented Jun 30, 2021 at 15:01
  • Removed the empty line . Still not working Commented Jun 30, 2021 at 15:06
  • 3
    This is from memory, but I think it needs to be data instead of Data. Will check when I’m at my computer. Commented Jun 30, 2021 at 15:38

1 Answer 1

1

The correct dictionary key for a figure is "data" rather than "Data":

fig = {
    "data": [
        go.Scatter(
            x=random_x,
            y=random_y,
            mode="markers",
        )
    ],
    "layout": go.Layout(title="My Scatter Plot"),
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.