How to hide time gaps financial stock market graph in Python?

Viewed 796

I'm trying to hide time gaps in the stock market. My problem is that I don't know how to use rangebreaks correctly in dash. https://plotly.com/python/reference/#layout-xaxis-rangebreaks https://plotly.com/python/time-series/

app = dash.Dash()

app.layout = html.Div([
   dcc.Graph(id='graph'),
   dcc.Dropdown(id='chooser',options=companies_options,value='CDPROJEKT')
])

@app.callback(Output('graph', 'figure'),
             [Input('chooser', 'value')])
def update_figure(selected_company):
   df_by_company = df_full[df_full['Nazwa'] == selected_company]
   df_by_company= df_by_company[(df_by_company['date'].dt.hour<17) & (df_by_company['date'].dt.hour>8)]
   traces = []
   print(df_by_company['date'].unique())
   traces.append(go.Scatter(
       x=df_by_company['date'],
       y=df_by_company['Kurs'],
       text=df_by_company['Nazwa'],
       mode='markers',
       opacity=0.7,
       #marker={'size': 15},
       name=selected_company
   ))

   return {
       'data': traces,
       'layout': go.Layout(
           xaxis= dict(title= 'Time',rangebreaks=[dict(bounds=[17, 8])]), 
           yaxis={'title': 'Price' },
           hovermode='closest'
       )
   }

if __name__ == '__main__':
   app.run_server()

This is my output graph. https://prnt.sc/rttbkk

Edit: When I simplified the code I found a solution for my problem.

import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import pandas as pd

df= pd.read_csv('cdr.csv')

app = dash.Dash()

app.layout = html.Div([dcc.Graph(id='scatterplot',
                    figure = {'data':[
                            go.Scatter(
                            x=df['date'],
                            y=df['price'],
                            mode='markers')],
                    'layout':go.Layout(title='My Scatterplot',
                                    xaxis= dict(title= 'Time', rangebreaks=[{ 'pattern': 'hour', 'bounds': [17.5, 8.5] } ]) )}
                    )])

if __name__ == '__main__':
    app.run_server()

My csv file looks like that:

date,number,price

2020-04-03 17:04:15,8838,297.0 https://prnt.sc/ruyob3
0 Answers
Related