0

I am updating a real-time candlestick chart project from mpl_finance to mplfinance, and some parts of the code stopped working. For example I am unable to draw horizontal lines once the chart is shown and being updated with new incoming candles.

First I added a listener to mouse movements:

fig.canvas.mpl_connect('motion_notify_event', on_move)

and then implemented the on_move method as follows:

def on_move(event):
if ax is not None:
    x, y = ax.transData.inverted().transform([event.x, event.y])
    d = num_to_date(x)
    if d in df.index:
        print(d, y)
        # USING MPL_FINANCE THE FOLLOWING WORKS
        # hl = plt.axhline(y=y, color='white', linestyle='-', alpha=1)
        # plt.draw()

        # TRIED THIS FOR THE CURRENT MPLFINANCE BUT NOTHING IS DRAWN
        mpf.plot(df, ax=ax, hlines=dict(hlines=[y], colors=['blue'], linestyle='-.', alpha=1))

The console shows the following: console

But the line is not drawn, even if add plt.draw() : chart

Please help.

MBS
  • 9
  • 3
  • Please provide the rest of your code, or at least enough, so that others can reproduce what you are seeing. Include some sample or dummy data to reproduce the problem. Also, you stated that `some parts of the code stopped working` which implies that you had it working previously ... therefore please provide the working version, and show what changes you made to get to the non-working version. Also please confirm, is it just the `hlines` that stopped working. What was the change that caused it to stop working? – Daniel Goldfarb Jan 03 '22 at 04:39
  • Please note, the appropriate technique for real-time plotting with the new API is [**documented here**](https://github.com/matplotlib/mplfinance/blob/master/markdown/animation.md). Please read that, and see how it relates to your existing code. – Daniel Goldfarb Jan 03 '22 at 04:43
  • After calling `mpf.plot()`, try calling `mpf.show()`. Lmk if that works. – Daniel Goldfarb Jan 03 '22 at 12:06
  • Please also indicate which matplotlib backend you are running. – Daniel Goldfarb Jan 03 '22 at 12:57

0 Answers0