Skip to main content
TopMiniSite

Back to all posts

How to Create Candlestick Chart Using Matplotlib?

Published on
5 min read
How to Create Candlestick Chart Using Matplotlib? image

Best Tools to Create Candlestick Charts to Buy in October 2025

1 12Pcs Trading Chart Pattern Posters Candlestick Pattern Poster Bulletin Board Crypto and Stock Market Trading Poster Office Decorations for Trader Investor Supplies Wall Door Decor 11 x 15.7 Inches

12Pcs Trading Chart Pattern Posters Candlestick Pattern Poster Bulletin Board Crypto and Stock Market Trading Poster Office Decorations for Trader Investor Supplies Wall Door Decor 11 x 15.7 Inches

  • COMPREHENSIVE SET: 12 POSTERS & 100 DOTS FOR EASY SETUP ANYWHERE.

  • EXQUISITE DESIGN: CLEAR PATTERNS ON SLEEK BLACK FOR QUICK REFERENCE.

  • PREMIUM QUALITY: DURABLE, LAMINATED POSTERS ENSURE LONG-LASTING USE.

BUY & SAVE
$14.99
12Pcs Trading Chart Pattern Posters Candlestick Pattern Poster Bulletin Board Crypto and Stock Market Trading Poster Office Decorations for Trader Investor Supplies Wall Door Decor 11 x 15.7 Inches
2 Gimly - Trading Chart (Set of 5) Pattern Posters, 350 GSM Candle Chart Poster, Trading Setup Kit for Trader Investor, (Size : 30 x 21 CM, Unframed)

Gimly - Trading Chart (Set of 5) Pattern Posters, 350 GSM Candle Chart Poster, Trading Setup Kit for Trader Investor, (Size : 30 x 21 CM, Unframed)

  • DURABLE 350 GSM PAPER ENSURES LONG-LASTING VIBRANT VISUALS.
  • GLOSS FINISH ENHANCES CLARITY FOR BETTER MARKET ANALYSIS.
  • PERFECT FOR STOCK AND CRYPTO TRADERS-BOOST YOUR TRADING STRATEGY!
BUY & SAVE
$9.97
Gimly - Trading Chart (Set of 5) Pattern Posters, 350 GSM Candle Chart Poster, Trading Setup Kit for Trader Investor, (Size : 30 x 21 CM, Unframed)
3 Candlestick Pattern Cheat Sheet for Trading – 3-Page Durable Cardstock with 190+ Chart Patterns – Includes Candlestick and Traditional Technical Analysis for Stock, Crypto, and Forex Traders

Candlestick Pattern Cheat Sheet for Trading – 3-Page Durable Cardstock with 190+ Chart Patterns – Includes Candlestick and Traditional Technical Analysis for Stock, Crypto, and Forex Traders

  • 190+ PATTERN LIBRARY: UNLOCK 190+ CHART PATTERNS FOR FASTER TRADING SUCCESS.

  • INFORMED TRADING DECISIONS: USE PROVEN PATTERNS TO BOOST YOUR TRADING STRATEGIES.

  • DURABLE & PORTABLE DESIGN: WATERPROOF CARDS FOR LONG-LASTING, ON-THE-GO TRADING.

BUY & SAVE
$19.99
Candlestick Pattern Cheat Sheet for Trading – 3-Page Durable Cardstock with 190+ Chart Patterns – Includes Candlestick and Traditional Technical Analysis for Stock, Crypto, and Forex Traders
4 Day Trading Flash Cards - Stock Market Chart & Candlestick Patterns, Instructions to Trade Like a Pro!

Day Trading Flash Cards - Stock Market Chart & Candlestick Patterns, Instructions to Trade Like a Pro!

  • ENHANCE TRADING SKILLS: PERFECT FOR BEGINNERS & SEASONED PROS ALIKE!

  • QUICK IDENTIFICATION: SWIFTLY RECOGNIZE KEY PATTERNS FOR BETTER TRADES.

  • DURABLE DESIGN: PORTABLE, HIGH-QUALITY CARDS FOR ON-THE-GO LEARNING!

BUY & SAVE
$19.95
Day Trading Flash Cards - Stock Market Chart & Candlestick Patterns, Instructions to Trade Like a Pro!
5 General Tools 715 Tap and Drill Reference Table

General Tools 715 Tap and Drill Reference Table

  • DOUBLE-SIDED DESIGN: TAP DRILL CHART & DECIMAL CONVERSIONS IN ONE TOOL.
  • ESSENTIAL FOR TOOLMAKERS: PRECISE REFERENCE FOR THREADS & CONVERSIONS.
  • 6-INCH RULER GRADUATED IN 64THS FOR ACCURATE MEASUREMENTS EVERY TIME.
BUY & SAVE
$9.80 $10.99
Save 11%
General Tools 715 Tap and Drill Reference Table
6 JIKIOU Stock Market Invest Day Trader Trading Mouse Pad Chart Patterns Cheat Sheet,X-Large Computer Mouse Pad/Desk Mat with Stitched Edges 31.5 x 11.8 in

JIKIOU Stock Market Invest Day Trader Trading Mouse Pad Chart Patterns Cheat Sheet,X-Large Computer Mouse Pad/Desk Mat with Stitched Edges 31.5 x 11.8 in

  • EXPERT TRADING AID: COMPREHENSIVE CHARTS AND INDICATORS FOR SUCCESS.

  • DURABLE DESIGN: NON-SLIP BASE AND WEAR-RESISTANT FOR LONG-LASTING USE.

  • STYLISH GIFT: PERFECT FOR BEGINNERS AND DAY TRADERS AIMING TO EXCEL.

BUY & SAVE
$9.99 $12.99
Save 23%
JIKIOU Stock Market Invest Day Trader Trading Mouse Pad Chart Patterns Cheat Sheet,X-Large Computer Mouse Pad/Desk Mat with Stitched Edges 31.5 x 11.8 in
7 DON'T TRADE BEFORE LEARNING THESE 14 CANDLESTICK PATTERNS: These 14 most reliable candlestick patterns provide to traders more than 85% of trade opportunities emanating from candlesticks trading.

DON'T TRADE BEFORE LEARNING THESE 14 CANDLESTICK PATTERNS: These 14 most reliable candlestick patterns provide to traders more than 85% of trade opportunities emanating from candlesticks trading.

BUY & SAVE
$7.99
DON'T TRADE BEFORE LEARNING THESE 14 CANDLESTICK PATTERNS: These 14 most reliable candlestick patterns provide to traders more than 85% of trade opportunities emanating from candlesticks trading.
8 Arrowbash Stock Trading Cards Trading Market Accessories Flash Cards 67 Charts Candlestick Pattern Accessories for Technical Analysis Ideal for Day Traders Swing Traders and Investors

Arrowbash Stock Trading Cards Trading Market Accessories Flash Cards 67 Charts Candlestick Pattern Accessories for Technical Analysis Ideal for Day Traders Swing Traders and Investors

  • MASTER TRADING WITH 67 CARDS: PATTERNS & EXAMPLES FOR ALL SKILL LEVELS.

  • PORTABLE DESIGN: FIT IN POCKET, DURABLE FOR EFFORTLESS MARKET ANALYSIS.

  • BOOST TRADING SPEED: INSTANT INSIGHTS TO SHARPEN YOUR STRATEGIES.

BUY & SAVE
$14.99
Arrowbash Stock Trading Cards Trading Market Accessories Flash Cards 67 Charts Candlestick Pattern Accessories for Technical Analysis Ideal for Day Traders Swing Traders and Investors
9 Trading: Technical Analysis Masterclass: Master the financial markets

Trading: Technical Analysis Masterclass: Master the financial markets

  • MASTER FINANCIAL MARKETS WITH EXPERT TECHNICAL ANALYSIS STRATEGIES.
  • LEARN EFFECTIVE TRADING TECHNIQUES FROM A PREMIUM QUALITY BOOK.
  • ELEVATE YOUR TRADING SKILLS WITH COMPREHENSIVE, ENGAGING CONTENT.
BUY & SAVE
$7.56
Trading: Technical Analysis Masterclass: Master the financial markets
+
ONE MORE?

To create a candlestick chart using matplotlib, you first need to import the necessary libraries, such as matplotlib, matplotlib.finance, and matplotlib.dates. Next, you would read in your financial data and convert it into a format that is compatible with matplotlib. Then, you can use the candlestick_ohlc function to plot the candlestick chart based on your data. Make sure to customize your chart by adding labels, titles, and adjusting the colors and styles of the candlesticks as needed. Finally, show the chart using plt.show(). Experiment with different parameters and settings to create a visually appealing and informative candlestick chart.

How to add axis labels to a candlestick chart in matplotlib?

To add axis labels to a candlestick chart in matplotlib, you can use the following code:

import matplotlib.pyplot as plt from mpl_finance import candlestick_ohlc import pandas as pd import matplotlib.dates as mdates

Create a dataframe with your data

For example:

data = {'date': ['2021-01-01', '2021-01-02', '2021-01-03'], 'open': [100, 110, 105], 'high': [120, 115, 118], 'low': [90, 105, 100], 'close': [110, 112, 115]} df = pd.DataFrame(data)

Convert date to matplotlib dates

df['date'] = pd.to_datetime(df['date']) df['date'] = df['date'].map(mdates.date2num)

Create the candlestick chart

fig, ax = plt.subplots() candlestick_ohlc(ax, zip(df['date'], df['open'], df['high'], df['low'], df['close']), width=0.6, colorup='g', colordown='r')

Set the x-axis labels

ax.xaxis_date() ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))

Set the y-axis labels

plt.xlabel('Date') plt.ylabel('Price')

plt.show()

This code will create a candlestick chart using the data from the dataframe df and add axis labels for the x-axis and y-axis. You can customize the labels further by changing the plt.xlabel() and plt.ylabel() functions to suit your needs.

How to create a candlestick chart with moving averages in matplotlib?

To create a candlestick chart with moving averages in matplotlib, you can follow these steps:

  1. Import the necessary libraries:

import matplotlib.pyplot as plt import pandas as pd import matplotlib.dates as mdates from mpl_finance import candlestick_ohlc

  1. Read the data into a pandas dataframe:

data = pd.read_csv('data.csv') data['Date'] = pd.to_datetime(data['Date']) data = data.set_index('Date')

  1. Calculate the moving averages:

data['MA_20'] = data['Close'].rolling(window=20).mean() data['MA_50'] = data['Close'].rolling(window=50).mean()

  1. Create the candlestick chart with moving averages:

fig, ax = plt.subplots() ax.xaxis_date()

candlestick_ohlc(ax, zip(mdates.date2num(data.index.to_pydatetime()), data['Open'], data['High'], data['Low'], data['Close']), width=0.6, colorup='g', colordown='r')

plt.plot(data.index, data['MA_20'], label='MA 20', color='blue') plt.plot(data.index, data['MA_50'], label='MA 50', color='orange')

plt.legend() plt.show()

This code reads the data from a CSV file, calculates the moving averages, and then plots a candlestick chart with the closing prices, along with the 20-day and 50-day moving averages. You can customize the chart further by adjusting the window size for the moving averages, changing the colors, or adding additional indicators.

How to add a legend to a candlestick chart in matplotlib?

To add a legend to a candlestick chart in matplotlib, you can use the matplotlib.pyplot.legend() function. Here is an example code snippet to demonstrate how to add a legend to a candlestick chart:

import matplotlib.pyplot as plt from mplfinance.original_flavor import candlestick_ohlc import matplotlib.dates as mdates import pandas as pd

Sample data

data = { 'date': pd.date_range(start='1/1/2021', periods=10), 'open': [100, 110, 120, 130, 140, 150, 160, 170, 180, 190], 'high': [120, 130, 140, 150, 160, 170, 180, 190, 200, 210], 'low': [90, 100, 110, 120, 130, 140, 150, 160, 170, 180], 'close': [110, 120, 130, 140, 150, 160, 170, 180, 190, 200] }

df = pd.DataFrame(data)

Create a figure and an axes

fig, ax = plt.subplots()

Plot the candlestick chart

candlestick_ohlc(ax, zip(mdates.date2num(df['date']), df['open'], df['high'], df['low'], df['close']), width=0.6, colorup='g', colordown='r')

Add legend

plt.legend(['Open', 'High', 'Low', 'Close'], loc='upper left')

Display the plot

plt.show()

In this example, we first create a candlestick chart using the candlestick_ohlc() function from the mplfinance.original_flavor module. Then, we use the plt.legend() function to add a legend to the plot, specifying the labels for each data series. Finally, we display the plot using plt.show().

What is a shooting star candlestick pattern?

A shooting star candlestick pattern is a bearish reversal pattern that typically occurs at the end of an uptrend. It is characterized by a small body at the top of the candle with a long upper shadow, and little to no lower shadow. The long upper shadow indicates that the price opened high, but was unable to sustain its momentum and closed near the low of the session, suggesting a potential reversal in the trend. Traders often see the shooting star as a sign of weakness and a potential signal to sell or go short.

How to add annotations to a candlestick chart in matplotlib?

You can add annotations to a candlestick chart in matplotlib by using the annotate function. Here is an example code snippet to add annotations to a candlestick chart:

import matplotlib.pyplot as plt from mpl_finance import candlestick_ohlc import pandas as pd import numpy as np

Create a sample dataframe with OHLC data

data = {'Date': pd.date_range(start='1/1/2021', periods=10), 'Open': np.random.randint(100, 200, 10), 'High': np.random.randint(200, 300, 10), 'Low': np.random.randint(50, 100, 10), 'Close': np.random.randint(100, 200, 10)} df = pd.DataFrame(data) df['Date'] = df['Date'].apply(lambda x: x.toordinal())

Create a figure and axis

fig, ax = plt.subplots()

Plot the candlestick chart

candlestick_ohlc(ax, df.values, width=0.6, colorup='g', colordown='r')

Add annotations to the chart

for i in range(len(df)): ax.annotate(str(df['Close'][i]), (df['Date'][i], df['High'][i]), textcoords="offset points", xytext=(0,10), ha='center')

plt.show()

In this code snippet, we first create a sample dataframe with OHLC data. We then plot the candlestick chart using the candlestick_ohlc function. Next, we loop through each data point in the dataframe and add annotations to the chart using the annotate function. The annotate function takes the text to display, the position of the annotation, the position of the text relative to the position, and the horizontal alignment of the text.

You can adjust the position and formatting of the annotations as needed to customize the appearance of the annotations on your candlestick chart.