Home > database >  Adding arrows to mpf finance plots
Adding arrows to mpf finance plots

Time:02-23

I am trying to add an arrow on a given date and price to mpf plot. To do this i have the following code:

import pandas as pd
import yfinance as yf
import datetime
from dateutil.relativedelta import relativedelta
import pandas as pd, mplfinance as mpf, matplotlib.pyplot as plt

db = yf.download(tickers='goog', start=datetime.datetime.now()-relativedelta(days=7), end= datetime.datetime.now(), interval="5m")
db = db.dropna()
a = db['Close'][31:32]
test =  mpf.make_addplot(a, type='scatter', markersize=200, marker='^')
mpf.plot(db, type='candle', style= 'charles', addplot=test)

But it is producing the following error:

ValueError: x and y must be the same size

Could you please advise how can i resolve this.

CodePudding user response:

The data passed into mpf.make_addplot() must be the same length as the dataframe passed into mpf.plot(). To plot only some points, the remaining points must be filled with nan values (float('nan'), or np.nan).

You can see this clearly enter image description here

  • Related