Skip to content

Using hour rangebreaks causes candlestick chart to fail #4795

Closed
@AndrewSovik

Description

@AndrewSovik

Using an hour rangebreak, in my case {'pattern': 'hour', 'bounds': [16, 9.5]} (2nd last line) causes the candlestick chart to not plot open/close boxes and it breaks the hovering feature to preview data. There is also more space between points but I assumed that was because the lack of candle boxes.

Data:
data.xlsx

Code:
`import pandas as pd
from plotly.offline import plot
import plotly.graph_objects as go
from plotly.subplots import make_subplots

df = pd.read_excel('data.xlsx')

#Plot Chart
fig = make_subplots(
rows=2, cols=1,
subplot_titles=('Price', 'Volume'),
shared_xaxes=True,
vertical_spacing=0.3)
fig.add_trace(go.Candlestick( #Candlesticks
x=df['date'], open=df['open'], high=df['high'], low=df['low'], close=df['close']),
row=1, col=1)
fig.add_trace(go.Bar( #Volume
x=df['date'], y=df['volume'],
marker_color='blue'),
row=2, col=1,)
fig.update_layout(
title_text='AAPL Technical Analysis',
xaxis_rangeslider_visible=True,
showlegend=False)
fig.update_xaxes(
rangebreaks=[
{'pattern': 'day of week', 'bounds': [6, 1]}, #Break weekends
{'pattern': 'hour', 'bounds': [16, 9.5]}]) #Break after hours and market close

plot(fig)`

Remove {'pattern': 'hour', 'bounds': [16, 9.5]} to see correct candlesticks but I don't want to plot times where the market is after hours or closed.

Python 3.7.7, all modules are updated

Thanks

Metadata

Metadata

Assignees

Labels

bugsomething broken

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions