Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Inspection error: <class 'IndexError'> list index out of range #520

Open
4 of 5 tasks
alexgiul opened this issue May 7, 2024 · 1 comment
Open
4 of 5 tasks
Labels
bug Something isn't working

Comments

@alexgiul
Copy link

alexgiul commented May 7, 2024

Requirements (place an x in each of the [ ])**

  • I realize finplot is not a web lib. (Hint: it's native!)
  • I've read the snippets and not found what I'm looking for.
  • I've searched for any related issues and avoided creating a duplicate issue.
  • 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

Screenshots

@alexgiul alexgiul added the bug Something isn't working label May 7, 2024
@highfestiva
Copy link
Owner

I'm guessing you've got a callback (from finplot.set_mouse_callback(... 'hover')) that is causing the list out of range. Add a try...except in your callback to figure out what you're doing wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants