在 Python 破折号中转换 Y 轴
Convert Y axis in Python dash
我有来自 csv 文件的数据
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
当我尝试显示带有破折号的图表时
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"},
},
),
...
不幸的是我得到了incorect plot
当我使用 go.figure 执行相同操作时:
import plotly.graph_objects as go
fig = go.Figure([go.Scatter(x=lec['LapNumber'], y=lec['LapTime'])])
我得到了correct plot
你知道如何在 dcc.Graph 上解决这个问题吗?
需要给 X 轴添加一些参数吗?
感谢提示
您可以采用这种方法:
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)
我有来自 csv 文件的数据
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 |
当我尝试显示带有破折号的图表时
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"},
},
),
...
不幸的是我得到了incorect plot
当我使用 go.figure 执行相同操作时:
import plotly.graph_objects as go
fig = go.Figure([go.Scatter(x=lec['LapNumber'], y=lec['LapTime'])])
我得到了correct plot
你知道如何在 dcc.Graph 上解决这个问题吗? 需要给 X 轴添加一些参数吗?
感谢提示
您可以采用这种方法:
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)