Available languages: [Python](https://databento.com/docs/examples/basics-historical/candlestick-plot.python.md) · [C++](https://databento.com/docs/examples/basics-historical/candlestick-plot.cpp.md) · [Rust](https://databento.com/docs/examples/basics-historical/candlestick-plot.rust.md) · [HTTP](https://databento.com/docs/examples/basics-historical/candlestick-plot.http.md) · [Raw](https://databento.com/docs/examples/basics-historical/candlestick-plot.raw.md)

Source: https://databento.com/docs/examples/basics-historical/candlestick-plot


# Plot a candlestick chart

## Overview

In this example we will use the [Historical client](https://databento.com/docs/api-historical/client.md) to retrieve AAPL pre-market one-minute OHLCV bars and plot a candlestick chart. A candlestick chart graphs the opening, high, low, and closing price at regular intervals. This is a common method for graphing price movements.

## OHLCV-1m schema

We'll demonstrate this example using the [OHLCV-1m schema](https://databento.com/docs/schemas/ohlcv.md).
The OHLCV family of schemas contain the opening, high, low and closing prices as well
as the aggregated volume of trades within a time interval. We'll use an interval of
one minute, a typical charting frequency, which is specified by the suffix `-1m`.

## Dependencies

This example will use the [mplfinance](https://pypi.org/project/mplfinance/) package to plot a candlestick chart.
This dependency can be installed with the following:

```bash
$ pip install mplfinance
```

## Example

```python
import databento as db
import mplfinance as mpf

# First, create a historical client
client = db.Historical(key="$YOUR_API_KEY")

# Next, we will request OHLCV-1m data for AAPL pre-market
data = client.timeseries.get_range(
    dataset="XNAS.ITCH",
    schema="ohlcv-1m",
    symbols=["AAPL"],
    start="2023-08-28T08:00:00-4",
    end="2023-08-28T09:30:00-4",
)

# Then, convert to a pandas DataFrame
df = data.to_df()

# Convert the index to the US/Eastern timezone
df.index = df.index.tz_convert("US/Eastern")

# Finally, plot the candlestick chart
mpf.plot(
    df,
    type="candle",
    volume=True,
    title="Nasdaq TotalView AAPL pre-market",
    ylabel="OHLCV-1M Candles",
    ylabel_lower="Volume",
    xlabel="Time",
)
```
## Result

![AAPL pre-market candlestick](https://databento.com/docs/candlestick-plot-0.png)
