gpt4 book ai didi

python - Plotly:行数 > 500 时不显示范围 slider

转载 作者:行者123 更新时间:2023-12-05 02:42:19 25 4
gpt4 key购买 nike

enter image description here

从图像中可以看出,rangeslider 的脚手架已生成,但其中的跟踪并未生成。否则它也可以完全发挥作用。通过一些实验,我发现只有你设置了 no。行到 500 或更少,它显示正确。有没有办法显示更多的行?这是重现的代码-

size = 501 #change this to change no. of rows

import numpy as np
import pandas as pd
import plotly.express as px

df = {'date': pd.date_range(start='2021-01-01', periods=size, freq='D'),
'new_cases': np.random.random(size=size),
'new_cases_smoothed': np.random.random(size=size)}

df = pd.DataFrame(df)
fig = px.line(df, x='date', y=['new_cases','new_cases_smoothed'])
fig.update_layout(xaxis=dict(rangeslider=dict(visible=True),type="date"))
fig.show()

最佳答案

这适用于graph_objects

size = 501 #change this to change no. of rows

import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go

df = {'date': pd.date_range(start='2021-01-01', periods=size, freq='D'),
'new_cases': np.random.random(size=size),
'new_cases_smoothed': np.random.random(size=size)}

df = pd.DataFrame(df)
# fig = px.line(df, x='date', y=['new_cases','new_cases_smoothed'])
fig = go.Figure(data=[go.Scatter(x=df["date"], y=df[c], name=c) for c in ['new_cases','new_cases_smoothed']])
fig.update_layout(xaxis={"rangeslider":{"visible":True},"type":"date",
"range":[df.tail(50)["date"].min(),df.tail(50)["date"].max()]})
fig.show()

关于python - Plotly:行数 > 500 时不显示范围 slider ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67671431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com