Search code examples
pythonplotcandlestick-chartmplfinance

How to add a simple horizontal line to mplfinance plot?


I know it may sound too simple but it got me stuck! I have a candle stick chart using fplt and I simply want to add a horizontal line to it but not sure how!

ax = fplt.plot(
                result,
                type='candle',
                style = 'charles',
                title='whatever!',
                ylabel='anything',figsize=(24,8)
            )

this creates my candle chart pretty well and nice as I wanted! but then I use ax.axhline(...) but gives me error or I use ax.plt(x_coordinates,y_coordinates) but again error: 'NoneType' object has no attribute 'plt'

can someone please make my life easier?! I just want to add a horizontal line here! thanks


Solution

  • With mplfinance, this is as simple as reading the mplfinance documentation, specifically the section titled Trends, Support, Resistance, and Trading Lines

    You can see there this is as simple as using the hlines kwarg:

    Also, mpf.plot() (or as you have unconventionally written, fplt.plot()) returns None, unless you set kwarg returnfig=True, but for what you want to do, there is no reason to access the Figure or Axes objects.

    hth