Skip to content

#316: Visualise Stock Market Data With mplfinance

Last week we used yfinance to fetch stock market data. In this post we explore our options to visualise them to get a better understanding of how the stock price moved around. For this task we use the library mplfinance. The library is a bit dated, but it gives us all the well-known visualisations without much effort at our end.

Installation

Mplfinance is built on top of Matplotlib and offers us utilities to visualise financial data. We can install the library with this command:

uv pip install mplfinance

Fetch the data

As described in the last post, we can use this code snipped to fetch the last 3 months of prices for the Nvidia stock with yfinance:

1
2
3
4
5
import mplfinance as mpf
import yfinance as yf

nvidia = yf.Ticker("NVDA")
df = nvidia.history(start="2025-10-01", end="2025-12-31")

OHLC chart

OHLC stands for open, high, low, close of a trading interval and is the default plot in mplfinance:

mpf.plot(df, type='ohlc', title="OHLC")

This creates a plot like this for our 3-month period with an indicator for each trading day:

The OHLC plot has a line between high and low and a horizontal (left) indicator for open and one for close (right).

Candlestick chart

Candlestick charts are commonly used in analytics, displaying one indicator per trading interval. The candle's body represents the open/close range; wicks show high and low prices. A green or white body means the stock closed higher, while red or black indicates it closed lower. We can create this type of plot with the type='candle' parameter:

mpf.plot(df, type='candle', title="Candle")

Each day gets its candle.

Line plot

If we prefer a minimalistic line plot, we can use the parameter type='line':

mpf.plot(df, type='line', title="Line")

This gives us a single line along the close prices of each trading interval:

A single line connecting all close prices.

Renko chart

A Renko chart highlights trends by showing only meaningful price movements. Each block (called a brick) is drawn only when the price moves by a predefined amount, what ignores small fluctuations of prices. We can create the plot with the type='renko' parameter:

mpf.plot(df, type='renko', title="Renko")

This gives us a good overview of the trend:

We see the end of an upwards trend, a single block for a down trend, followed by a upwards trend that got a larger setback in the middle.

Include the volume

Another important indicator is the volume of shares traded. We can add this information with the volume=True parameter to any of the plots:

mpf.plot(df, type='candle',volume=True, title="Candle With Volume")

This creates a candlestick plot and adds the volume of traded stocks below:

The volume is below the candlestick plot.

Moving averages

Moving averages help us to see the trend more clearly by averaging past prices over time. We can set whatever values we want and pass them to our plot with the mav=() parameter:

mpf.plot(df, type='candle',mav=(5,10,20), title="Candle + Moving Average 5, 10 & 20 Days")

This gives us an average line for each interval we specified on top of our plot:

We now get a candlestick plot with lines for the moving average of 5, 10 and 20 days.

Next

To identify outliers and errors in stock market data, we can use a library like mplfinance to quickly generate visualisations such as candlestick or Renko charts. These visualisations make it easy to spot major trends or shifts in trading volume with minimal coding effort. Next week we play around with the stock market data and compare a few stocks.