Home > front end >  How to plot a horizontal line starting from a specific date in a Japanese Candlestick chart using Ma
How to plot a horizontal line starting from a specific date in a Japanese Candlestick chart using Ma

Time:09-26

I recently decided to code a small program in Python3 that plots the OHLC prices stored in a dataframe and also highlights a horizontal line for a specific price on said graph. For this work, the initial graph

However, I am interested in learning how someone can specify the start date from which the horizontal line in the figure above would be drawn, so that this horizontal line does not go over the entire graph but only over those values after the start date, that is, a graph like the following:

desired graph

If it's not too much trouble, I would also like to know how I could add a small label to said horizontal line as shown in the image.

I appreciate anyone who can help me out.

CodePudding user response:

The mplfinance kwarg hlines is by definition all the way from one side of the plot to the other. To plot a horizontal line that does not stretch from one side to the other, use kwarg alines.

To add text or an annotation near the line, use axlist[0].text() or axlist[0].annotate()

  • Related