Plotly:行数 > 500 时不显示范围滑块
Plotly: Range slider not being displayed for row count > 500
从图像中可以看出,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()
对于其他使用 plotly.express
的人,我幸运地设置了 kwarg render_mode='webg1'
:
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'], render_mode='webg1')
fig.update_layout(xaxis=dict(rangeslider=dict(visible=True),type="date"))
fig.show()
从图像中可以看出,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()
对于其他使用 plotly.express
的人,我幸运地设置了 kwarg render_mode='webg1'
:
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'], render_mode='webg1')
fig.update_layout(xaxis=dict(rangeslider=dict(visible=True),type="date"))
fig.show()