Search code examples
pythonpython-3.xkeyerrormplfinance

KeyError when bbox_inches='tight' in mplfinance plot


I have the following code: from pandas_datareader import data as web

import pandas as pd
from datetime import timedelta  
import mplfinance as mpf
import matplotlib as plt
df = web.DataReader('goog','yahoo', start="2021-07-3", end="2021-09-12")
mpf.plot(df, style='charles', type = 'candle', volume=True, figratio=(12,8), bbox_inches='tight')

bbox_inches='tight' is throwing an error:

KeyError: 'Unrecognized kwarg="bbox_inches"'

How can i make margins tight?


Solution

  • Use kwarg tight_layout=True.

    If that doesn't do what you want you can also try kwarg scale_padding as described here.

    bbox_inches can only be used in conjunction with kwarg savefig kwarg. See here for details.