finplot
finplot copied to clipboard
[BUG] Inspection error: <class 'IndexError'> list index out of range
Requirements (place an x
in each of the [ ]
)**
- [x] I realize finplot is not a web lib. (Hint: it's native!)
- [x] I've read the snippets and not found what I'm looking for.
- [x] I've searched for any related issues and avoided creating a duplicate issue.
- [x] I've updated finplot (
pip install -U finplot
). - [ ] I've supplied the required data to run my code below.
Code to reproduce
#☺ initialization code
# https://github.com/highfestiva/finplot/blob/master/finplot/examples/embed.py
# small customization
fplt.candle_bull_body_color = fplt.candle_bull_color
fplt.legend_fill_color = '#fff'
fplt.legend_text_color = '#000'
fplt.display_timezone = timezone.utc
self.ax = fplt.create_plot('beyond_horizon', init_zoom_periods=100, yscale='linear')
self.ax.showGrid(True, True)
self.ax_volume = self.ax.overlay()
fplt.set_mouse_callback(self.on_move, ax=self.ax, when='hover')
self.plot_candles = fplt.live(1)
fplt.timer_callback(self.plot_candlestick_chart, 10)
#fplt.show()
self.chart.addWidget(self.ax.vb.win)
Plotting code:
def plot_candlestick_chart(self, hard_reset=False):
self.logger.info(f"plot_candlestick_chart")
candle_sizes = self.cmb_candle_size.currentText().split(",")
try:
candle_sizes = [int(val.strip()) for val in candle_sizes] # remove spaces
except:
self.logger.warning("wrong candle sizes")
return
ticker = self.cmb_ticker.currentText()
show_volume = self.checkbox_volume.isChecked()
self.ticker_subscribe.emit(ticker, int(candle_sizes[0]))
if candle_sizes[0] not in self.dfs:
return
# save window zoom position before resetting
if not hard_reset:
fplt.autoviewrestore()
fplt._savewindata(fplt.windows[0])
else:
fplt.autoviewrestore(enable=False)
if self.current_bar.close !=0:
df = pd.DataFrame([self.current_bar], columns=Bar._fields)
df.index = pd.DatetimeIndex(df['date']) # convert to datetimeindex
df_updating = pd.concat([ self.dfs[candle_sizes[0]], df])
price = df_updating['open close high low'.split()]
else:
price = self.dfs[candle_sizes[0]]['open close high low'.split()]
self.plot_candles.candlestick_ochl(price)
if show_volume is True:
volume = self.dfs[candle_sizes[0]]['open close volume'.split()]
self.ax_volume.reset() # remove previous plots
fplt.volume_ocv(volume, ax=self.ax_volume)
# restores saved zoom position, if in range
fplt.refresh() # refresh autoscaling when all plots complete
Describe the bug
In some cases, not clear when I start getting this errors on console; this happens when I move the mouse over the chart. Inspection error: <class 'IndexError'> list index out of range Inspection error: <class 'IndexError'> list index out of range Inspection error: <class 'IndexError'> list index out of range Inspection error: <class 'IndexError'> list index out of range
Expected behavior
Understand what is wrong