Home > Back-end >  Convert Y axis in Python dash
Convert Y axis in Python dash

Time:04-07

I have a data from csv file

id lap_time LapNumber
175 0 days 00:02:04.853000 2
176 0 days 00:02:01.375000 3
177 0 days 00:01:59.889000 4
178 0 days 00:01:58.425000 5
179 0 days 00:01:57.786000 6
180 0 days 00:02:10.329000 7
181 0 days 00:01:53.315000 8
182 0 days 00:01:49.771000 9

when I try to display a graph with a dash

import dash
from dash import dcc
from dash import html
import pandas as pd
import fastf1
from fastf1 import plotting
import plotly.express as px
...
...
        dcc.Graph(
            figure={
                "data": [
                    {
                        "x": lec['LapNumber'],
                        "y": lec['LapTime'],
                        "type": "lines",
                    },
                ],
                "layout": {"title": "Test Date"},
            },
        ),
...

Unfortunately I gets incorect plot

When I do the same using go.figure:

import plotly.graph_objects as go
fig = go.Figure([go.Scatter(x=lec['LapNumber'], y=lec['LapTime'])])

I got correct plot

Do you know how to solve this issue on dcc.Graph ? Need to add some parameters to X axis ?

Thanks for hint

CodePudding user response:

You can follow this approach:

from dash import dcc
import plotly.graph_objs as go

fig = go.Figure([go.Scatter(x=lec['LapNumber'], y=lec['LapTime'])])

dcc.Graph(figure=fig)
  • Related