Registry / data / mplfinance

mplfinance

JSON →
library0.12.10b0pypypi✓ verified 22d ago

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.

pip install mplfinance
INSTALL
IMPORT
SIG · MPLFINANCE
M
mplfinance
datapythonv0.12.10b0
Install
11.5s avg
Import
3212ms
Disk
256MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.12.10b0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 3.287s · 253.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 11.5s · import 3.138s · 242MB
256MB installed
● package 256MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

mpf
import mplfinance as mpf

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.

import mplfinance as mpf import pandas as pd import numpy as np # Create dummy OHLCV data with DatetimeIndex dates = pd.date_range('2023-01-01', periods=50, freq='D') np.random.seed(42) open_price = np.random.rand(50) * 100 + 100 close_price = open_price + np.random.randn(50) * 5 high_price = np.maximum(open_price, close_price) + np.random.rand(50) * 2 low_price = np.minimum(open_price, close_price) - np.random.rand(50) * 2 volume = np.random.rand(50) * 1000000 df = pd.DataFrame({ 'Open': open_price, 'High': high_price, 'Low': low_price, 'Close': close_price, 'Volume': volume }, index=dates) # Plot a basic candlestick chart with volume fig, axes = mpf.plot(df, type='candle', style='yahoo', volume=True, title='Sample Candlestick Chart', ylabel='Price', ylabel_lower='Volume', returnfig=True ) # To display the plot in a non-interactive environment or save it # fig.savefig('candlestick_chart.png') # import matplotlib.pyplot as plt # plt.show() # Uncomment for interactive display
Debug
Known issues
gotchamplfinance 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.
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.
affects: All versions
deprecatedOlder 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.
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.
affects: < 0.12.9b7
gotchaDirect 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.
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`).
affects: All versions
gotchamplfinance 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.
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.
affects: All pre-release (`b`) versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'mplfinance'
The `mplfinance` library is not installed in the Python environment being used, or there is a conflict with an old, deprecated `mpl_finance` installation.
fix
Ensure `mplfinance` is installed by running `pip install --upgrade mplfinance`. If using a virtual environment or Jupyter, confirm it's installed in the correct environment.
KeyError: 'Open'
`mplfinance` expects the input Pandas DataFrame to have specific column names: 'Open', 'High', 'Low', 'Close', and optionally 'Volume' (case-sensitive). This error occurs when one or more of these expected columns are missing or incorrectly named.
fix
Rename your DataFrame columns to match the expected 'Open', 'High', 'Low', 'Close', and 'Volume' (with correct capitalization) before passing it to `mpf.plot()`. Ensure the index is a DatetimeIndex.
ValueError: Data must be a DataFrame with a DateTimeIndex
`mplfinance` requires the input data to be a Pandas DataFrame where the index is of `DatetimeIndex` type, which is crucial for time-series plotting.
fix
Convert the DataFrame's index to a `DatetimeIndex` using `pd.to_datetime()` and `df.set_index()` if your date/time column is not already the index or is not in datetime format.
mplfinance error,Data for column "Open" must be ALL float or int
The data within the 'Open', 'High', 'Low', 'Close', or 'Volume' columns of the DataFrame contains non-numeric values (e.g., strings), while `mplfinance` expects these financial data points to be entirely of float or integer type.
fix
Inspect the data types of your OHLCV columns using `df.dtypes`. Convert any non-numeric data in these columns to float or int using `pd.to_numeric(df['Column'], errors='coerce')` to handle potential non-convertible values gracefully.
ValueError: x and y must be the same size
This error typically occurs when using `mpf.make_addplot()` to add overlay plots (e.g., scatter plots for signals or additional lines) where the data array for the overlay does not have the same number of elements as the main OHLCV data being plotted.
fix
Ensure that any data passed to `mpf.make_addplot()` (especially for scatter plots or lines) has the exact same length and DateTimeIndex as the main DataFrame passed to `mpf.plot()`. Often, this means creating a Series filled with `np.nan` for non-signal points and only populating the signal points.
Upgrade
Version history
0.12.10b0latest on PyPI · released Aug 2, 2023
Audit
Dependencies
matplotlibrequiredCore plotting library, mplfinance is built on top of it.
pandasrequiredRequired for data handling, especially DataFrames and DatetimeIndex.
Agent activity
9 hits · last 30 days
node
6
Resources
mplfinance — pip install mplfinance · libregistry