{"id":4989,"library":"mplfinance","title":"Matplotlib Finance (mplfinance)","description":"mplfinance is a Python library built on Matplotlib and Pandas for the visualization and visual analysis of financial data. It specializes in generating highly customizable candlestick, OHLC, and Renko charts, often with integrated volume, moving averages, and other technical indicators. It is currently in active development, releasing frequent beta versions (latest is 0.12.10b0) with ongoing feature enhancements and bug fixes.","status":"active","version":"0.12.10b0","language":"en","source_language":"en","source_url":"https://github.com/matplotlib/mplfinance","tags":["finance","plotting","candlestick","ohlc","technical analysis","matplotlib","pandas"],"install":[{"cmd":"pip install mplfinance","lang":"bash","label":"Install stable version"},{"cmd":"pip install --pre mplfinance","lang":"bash","label":"Install latest pre-release (beta)"}],"dependencies":[{"reason":"Core plotting library, mplfinance is built on top of it.","package":"matplotlib","optional":false},{"reason":"Required for data handling, especially DataFrames and DatetimeIndex.","package":"pandas","optional":false}],"imports":[{"symbol":"mpf","correct":"import mplfinance as mpf"}],"quickstart":{"code":"import mplfinance as mpf\nimport pandas as pd\nimport numpy as np\n\n# Create dummy OHLCV data with DatetimeIndex\ndates = pd.date_range('2023-01-01', periods=50, freq='D')\nnp.random.seed(42)\nopen_price = np.random.rand(50) * 100 + 100\nclose_price = open_price + np.random.randn(50) * 5\nhigh_price = np.maximum(open_price, close_price) + np.random.rand(50) * 2\nlow_price = np.minimum(open_price, close_price) - np.random.rand(50) * 2\nvolume = np.random.rand(50) * 1000000\n\ndf = pd.DataFrame({\n    'Open': open_price,\n    'High': high_price,\n    'Low': low_price,\n    'Close': close_price,\n    'Volume': volume\n}, index=dates)\n\n# Plot a basic candlestick chart with volume\nfig, axes = mpf.plot(df, \n                     type='candle', \n                     style='yahoo', \n                     volume=True, \n                     title='Sample Candlestick Chart',\n                     ylabel='Price',\n                     ylabel_lower='Volume',\n                     returnfig=True\n                    )\n\n# To display the plot in a non-interactive environment or save it\n# fig.savefig('candlestick_chart.png')\n# import matplotlib.pyplot as plt\n# plt.show() # Uncomment for interactive display","lang":"python","description":"This quickstart generates dummy OHLCV data using Pandas and NumPy, then plots a basic candlestick chart with volume using `mpf.plot()`. It demonstrates the required DataFrame format (DatetimeIndex, specific column names) and common plotting parameters like `type`, `style`, and `volume`. The `returnfig=True` argument allows access to the underlying Matplotlib Figure and Axes objects for further customization or saving."},"warnings":[{"fix":"Ensure your DataFrame's index is `pd.DatetimeIndex` and column names are exactly 'Open', 'High', 'Low', 'Close', 'Volume'. Use `df.rename()` or `df.columns = [...]` if necessary.","message":"mplfinance expects input data as a Pandas DataFrame with a DatetimeIndex and specific column names (case-sensitive): 'Open', 'High', 'Low', 'Close', and optionally 'Volume'. Incorrect indexing or column naming will lead to errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade mplfinance to version 0.12.9b7 or newer to benefit from fixes addressing deprecation warnings and improved compatibility with modern Matplotlib/Pandas releases. Also ensure Matplotlib and Pandas are up-to-date.","message":"Older versions of mplfinance (prior to 0.12.9b7) may issue deprecation warnings or encounter compatibility issues when run with recent versions of Matplotlib or Pandas.","severity":"deprecated","affected_versions":"< 0.12.9b7"},{"fix":"Use `mpf.make_addplot()` to create 'addplot' objects for overlay data (e.g., scatter plots, lines), then pass a list of these objects to the `addplot` keyword argument of `mpf.plot()`. For general chart customization, explore `mpf.plot()`'s extensive keyword arguments (e.g., `style`, `marketcolors`).","message":"Direct manipulation of Matplotlib Axes objects returned by `mpf.plot()` can be challenging due to mplfinance's internal panel structure. For overlaying custom data series or indicators, the `addplot` kwarg is the idiomatic approach.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When using pre-release versions, review the GitHub changelog for each update. For production environments requiring strict stability, consider pinning to exact minor versions.","message":"mplfinance frequently releases beta versions (e.g., `0.12.10b0`) which may introduce minor API changes or new features that are refined rapidly. While generally stable, users should monitor release notes carefully.","severity":"gotcha","affected_versions":"All pre-release (`b`) versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}