mplfinance icon indicating copy to clipboard operation
mplfinance copied to clipboard

Feature Request: HLines on AddPlot

Open luongjames8 opened this issue 4 years ago • 4 comments

Is it possible to implement hlines (and vlines) for addplots. Right now they’re only available on the primary panel.

The vlines functionality might require a bit more thought as it seems more intuitive that the vlines would slice through all the charts vertically. But I suppose an easy work around would just be the draw the same vertical line on the main plot and addplot for now.

luongjames8 avatar Jul 02 '20 10:07 luongjames8

duplicate of #140

DanielGoldfarb avatar Jul 02 '20 11:07 DanielGoldfarb

Hi @luongjames8,

In the mean time, you can easily add hlines to addplots like so:

# Suppose you have DataFrame Column with 'LOGRET'
cumlog_return = df['LOGRET'].cumsum() # cumulative log return
hline0 = [0] * df.shape[0] # You need a hline=0

ap0 = [
    mpf.make_addplot(cumlog_return, color='black', panel=2)
    mpf.make_addplot(hline0, color='gray', panel=2) 
]

mpf.plot(
    df, type="candle", volume=True, addplot=ap0,
    figscale=1.8, panel_ratios=(7, 2, 2), style='classic',
    title=f"\n{ticker}",
)

Hope this helps! KJ

twopirllc avatar Jul 06 '20 03:07 twopirllc

Thanks KJ - will give this a try!

luongjames8 avatar Jul 06 '20 04:07 luongjames8

Hi @luongjames8,

In the mean time, you can easily add hlines to addplots like so:

# Suppose you have DataFrame Column with 'LOGRET'
cumlog_return = df['LOGRET'].cumsum() # cumulative log return
hline0 = [0] * df.shape[0] # You need a hline=0

ap0 = [
    mpf.make_addplot(cumlog_return, color='black', panel=2)
    mpf.make_addplot(hline0, color='gray', panel=2) 
]

mpf.plot(
    df, type="candle", volume=True, addplot=ap0,
    figscale=1.8, panel_ratios=(7, 2, 2), style='classic',
    title=f"\n{ticker}",
)

Hope this helps! KJ

And what about adding vlines on panels? Is there some workaround?

k1mbl3 avatar Dec 04 '20 16:12 k1mbl3