How to add value of hlines in y axis using mplfinance python

Viewed 293

Hello everyone and thank you for your help in advance. I have managed to plot a candlestick chart using mplfinance module in python and I have added some hlines to my plot. The problem is, I can't figure out how to add hlines value to yaxis of my chart.

here is my code: mpf.plot(hloc,hlines=dict(hlines=clusters_centers,colors=['blue'],linestyle='-.'), ylabel='Price', type='candle', style='binance')

and this is how my plot looks like candlestick + hlines

1 Answers

Try the following: Set returnfig=True to gain access to the Figure and Axes objects, then use matplotlib's Axes.text() or Axes.annotate() to label your hlines:

hlines=dict(hlines=clusters_centers,colors=['blue'],linestyle='-.')

fig, axlist = mpf.plot(hloc,hlines=hlines,
                       ylabel='Price',type='candle', 
                       style='binance',returnfig=True)

x = len(hloc)
for y in cluster_centers:
    axlist[0].annotate(str(y),(x,y))

mpf.show()
Related