2

I need to add to the plot some text and I tried to use your guide "How to use your own matplotlib Figure and Axes in mplfinance". But i have an error:

"ValueError: make_addplot() ax kwargs must all be of type matplotlib.axis.Axes"

My code:


    import mplfinance as fplt
    import pandas as pd
    
    df5M = pd.read_csv("D:\\_users_files\\Kirill\\WORK\\fx2youcom\\df5M.csv", index_col=0, parse_dates=True)
    
    
    fig = fplt.figure(style='yahoo', figsize=(10.8, 6.4))
    
    ax1 = fig.add_subplot(2, 2, 1)
    
    sma = [fplt.make_addplot(df5M['SMA20'].tail(100), color='#f1afe1'),
           fplt.make_addplot(df5M['SMA50'].tail(100), color='#ffaf6c'),
           fplt.make_addplot(df5M['SMA200'].tail(100), color='#f0dea7')]
    
    fplt.plot(df5M.tail(100),
              type='candle',
              ax=ax1,
              style='yahoo',
              title="long_name",
              ylabel='5 Minutes',
              addplot=sma
              )
    fig

Kyrylo
  • 45
  • 1
  • 6
  • Is there an example of the output you expect? How do you want to add the text? Also, you specify subplots, do you want to specify 'SMA20', 'SMA50', 'SMA200', and 'candle'? – r-beginners Jun 06 '21 at 14:14

1 Answers1

1

Whenever you pass an external Axes object into mplfinance.plot() using the ax= kwarg, then

  • if you want to plot volume, then you must pass an Axes object in for the volume:
    that is, instead of volume=True do volume=axes where axes is an Axes object on which you want to plot the volume.
  • you must also use kwarg ax= for all calls to mplfinance.make_addplot()

This information was noted at the bottom of the subplots page.
Probably should also be included in the external axes notebook.

Daniel Goldfarb
  • 6,937
  • 5
  • 29
  • 61