Plotly: Range slider not being displayed for row count > 500

cal*_*ant 5 python customization data-visualization plotly plotly-python

在此输入图像描述

从图像中可以看出,范围滑块的脚手架已生成,但其内部的迹线并未生成。除此之外,它的功能也很齐全。通过一些实验,我发现只有当你设置 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()
Run Code Online (Sandbox Code Playgroud)

Cla*_*ade 5

对于其他使用的人来说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()
Run Code Online (Sandbox Code Playgroud)


Rob*_*ond 2

这适用于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()

Run Code Online (Sandbox Code Playgroud)