Typical Usage¶
In [1]:
Copied!
from mplchart.chart import Chart
from mplchart.samples import sample_prices
from mplchart.primitives import Candlesticks, Volume, Pane, LinePlot
from mplchart.indicators import SMA, RSI, MACD
from mplchart.chart import Chart
from mplchart.samples import sample_prices
from mplchart.primitives import Candlesticks, Volume, Pane, LinePlot
from mplchart.indicators import SMA, RSI, MACD
In [2]:
Copied!
prices = sample_prices()
prices
prices = sample_prices()
prices
Out[2]:
| open | high | low | close | volume | |
|---|---|---|---|---|---|
| date | |||||
| 1980-12-12 | 0.098389 | 0.098817 | 0.098389 | 0.098389 | 469033600 |
| 1980-12-15 | 0.093684 | 0.093684 | 0.093256 | 0.093256 | 175884800 |
| 1980-12-16 | 0.086839 | 0.086839 | 0.086412 | 0.086412 | 105728000 |
| 1980-12-17 | 0.088550 | 0.088978 | 0.088550 | 0.088550 | 86441600 |
| 1980-12-18 | 0.091118 | 0.091545 | 0.091118 | 0.091118 | 73449600 |
| ... | ... | ... | ... | ... | ... |
| 2025-11-11 | 269.809998 | 275.910004 | 269.799988 | 275.250000 | 46208300 |
| 2025-11-12 | 275.000000 | 275.730011 | 271.700012 | 273.470001 | 48398000 |
| 2025-11-13 | 274.109985 | 276.700012 | 272.089996 | 272.950012 | 49602800 |
| 2025-11-14 | 271.049988 | 275.959991 | 269.600006 | 272.410004 | 47399300 |
| 2025-11-17 | 268.815002 | 270.489990 | 265.730011 | 267.459991 | 42862157 |
11325 rows × 5 columns
In [3]:
Copied!
(Chart(prices, title="Example Chart", max_bars=250)
.plot(
Candlesticks(), Volume(), SMA(50), SMA(200),
Pane("above", yticks=(30, 50, 70)),
LinePlot(RSI(), overbought=70, oversold=30),
Pane("below"),
MACD(),
)
.show()
)
(Chart(prices, title="Example Chart", max_bars=250)
.plot(
Candlesticks(), Volume(), SMA(50), SMA(200),
Pane("above", yticks=(30, 50, 70)),
LinePlot(RSI(), overbought=70, oversold=30),
Pane("below"),
MACD(),
)
.show()
)
What about polars?¶
This walkthrough uses pandas data, but mplchart works the same with polars DataFrames — the charting layer is identical, with polars expressions taking the place of indicators. See the Pandas and Polars Backends reference page and the How Expressions Work tutorial.