Hi,
Iām a relatively new Plotly user. Iām experiencing the same issue as this post, where the data isnāt being shown for range selectors and slider. However, the suggested workaround (i.e., explicitly set the range for slider) isnāt solving the issue. Iāve also looked at the related reference docs like this one and this one. Hereās the starting image.
For instance, if I select 1M, I donāt see any data. Similarly, if I select 3M, I only see part of the data (i.e., 2 data points). The only selectors that are correctly working are all and ytd. In the code below, Iāve included a sizable test sample for reproducibility.
One thing that I noticed is that the number of data points is impacting whether or not the problem occurs. If you only plot the first (or last) six data points, everything displays fine.
Any guidance would be greatly appreciated. If itās a bug, hopefully someone at Plotly will see this post and say the same.
Iām running the following versions in a condo environment:
plotly 4.6.0
Python 3.7.7
jupyter notebook 6.0.3
pandas 1.0.3
numpy 1.18.1
Matplotlib 3.1.3
Hereās the code. Itās largely based on the Plotly documentation.
# Imports used earlier in the code, but not necessarily in this reproducible example
%matplotlib inline
import numpy as np
import pandas as pd
import plotly.graph_objects as go
from datetime import datetime
from plotly import offline
# Create figure
fig = go.Figure()
# Data Set
dates=[
'2018-03-31',
'2018-04-30',
'2018-05-31',
'2018-06-30',
'2018-07-31',
'2018-08-31',
'2018-09-30',
'2018-10-31',
'2018-11-30',
'2018-12-31',
'2019-01-31',
'2019-02-28',
'2019-03-31',
'2019-04-30',
'2019-05-31',
'2019-06-30',
'2019-07-31',
'2019-08-31',
'2019-09-30',
'2019-10-31',
'2019-11-30',
'2019-12-31',
'2020-01-31',
'2020-02-29',
'2020-03-31',
]
metric=[
65,
254,
341,
317,
281,
290,
245,
165,
269,
203,
212,
259,
246,
174,
332,
305,
298,
283,
236,
273,
277,
263,
334,
337,
237,
]
# Add traces
fig.add_trace(go.Scatter(
x=dates,
y=metric,
mode='lines+markers',
marker=dict(symbol='circle'),
line=dict(
color='royalblue',
width=2,
),
name='Metric'),
)
# Add range selectors and slider
fig.update_layout(
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=1,
label="1M",
step="month",
stepmode="backward"),
dict(count=3,
label="3M",
step="month",
stepmode="backward"),
dict(count=6,
label="6M",
step="month",
stepmode="backward"),
dict(count=1,
label="YTD",
step="year",
stepmode="todate"),
dict(count=1,
label="1Y",
step="year",
stepmode="backward"),
dict(label="All",
step="all")
])
),
rangeslider=dict(
visible=True,
range=(dates[0], dates[-1])
),
type="date"
)
)
fig.show()