plotly / plotly/plotly.py

Plotly Weekly & Monthly Range selector buttons not working on time series data

Đang mở
#3,845 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

bug P3
Ngôn ngữ chính
Python
Star
18.8k
Fork
2.8k
Merge trung bình
16 giờ 26 phút
Pull request đã merge (30 ngày)
21

Mô tả

Hi,

I am having last 1 year time series financial data. I removed weekends as no data is present.

I created plotly viz, 2w,1m range selector buttons are not showing correct time range. While YTD,6m,all showing correct data.

2w button showing 2 week forward days but there is no data, want to see last two week and 1m data.

Reproducable Code-

# !pip install investpy
import pandas as pd
import investpy
import plotly.graph_objects as go
import plotly.figure_factory as ff
import plotly.express as px

today = datetime.now()  #Today Datetime
today_fut = today.strftime("%Y,%m,%d") #Converting today date to string format "%Y,%m,%d"
today_fut = datetime. strptime(today_fut, '%Y,%m,%d').date() #Converting today's date to "date" format for NSE Tools library
today = today.strftime("%d/%m/%Y") #Converting today date to string format "%d/%m/%Y"
one_year= datetime.today() - timedelta(days=370) #Subrtracting todays date with 370 Days
one_year = one_year.strftime("%d/%m/%Y") #Converting into  string format "%d/%m/%Y"

df = investpy.get_index_historical_data(index="Nifty 50",country="India",from_date=str(one_year),to_date= str(today))
print("Investpy NF Dataframe",df.tail())

bnf = investpy.get_index_historical_data(index="Nifty Bank",country="India",from_date=str(one_year),to_date= str(today))
print("Investpy BNF Dataframe",bnf.tail())

fig = go.Figure(data = [ go.Scatter(x = df.index,y = df['Close'],line=dict(color = 'Steelblue',width=2),mode='lines+markers',name = 'NIFTY'),
                        go.Scatter(x = bnf.index,y = bnf['Close'],line=dict(color = 'yellowgreen',width=2),mode='lines+markers',name = 'BANK NIFTY'),
                        ])
fig.update_layout(
    title='NF and BNF',template = 'plotly_dark',xaxis_tickformat = ' %d %B (%a)<br> %Y',
    yaxis_title='NF & BNF',yaxis_tickformat= "000",yaxis_side = 'right',xaxis_title='Date',legend = dict(bgcolor = 'rgba(0,0,0,0)'))

layout = go.Layout(showlegend=True)

##https://plotly.com/python/legend/
fig.update_layout(legend=dict(
    yanchor="top",
    y=0.99,
    xanchor="left",
    x=0.01  ))
#hide weekends
fig.update_xaxes( rangeslider_visible=True, rangebreaks=[
        dict(bounds=["sat", "mon"]) ])
##https://plotly.com/python/legend/
fig.update_layout(legend=dict(
    orientation="h",
    yanchor="bottom",
    y=1.02,
    xanchor="right",
    x=1
))


config = dict({'scrollZoom': False})

fig.update_layout(
    xaxis=dict(rangeselector=dict(buttons=list([
               dict(count=14,label="2w",step="day",stepmode="todate"),
               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(step="all") ])),rangeslider=dict(visible=True),type="date"))
fig.update_layout(
                  xaxis_rangeselector_font_color='white',
                  xaxis_rangeselector_activecolor='red',
                  xaxis_rangeselector_bgcolor='green',
                 )
 
fig.show()
pio.write_html(fig, file='wrong_range_selecor_for-2w&1m_button.html', auto_open=True)

Pls let me know , if there is any bug in plotly range selector or I am doing something wrong in
xaxis=dict(rangeselector=dict(buttons=list([xaxis=dict(rangeselector=dict(buttons=list([ code.
I tried dict(count=14,label="2w",step="day",stepmode="backward") but still same issue.

Snaps-
When I click on 2w but it show future dates, where no data is present in dataframe.
image

1m button snap-
image

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách chạy ví dụ Python có thể tái hiện với các nút xaxis.rangeselector và cấu hình rangebreaks được hiển thị trong issue. So sánh hành vi của todatebackward đối với các nút 2w1m trên chỉ mục ngày giao dịch; hoàn tất khi các khoảng được chọn kết thúc tại dữ liệu mới nhất hiện có và hiển thị đúng khoảng thời gian lịch sử dự kiến.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
plotly, python
Lĩnh vực
data-visualization
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.