Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Candlestick Chart

Signature

sp.build_candlestick(
    title: str,
    dates: list[str],
    opens: list[float],
    highs: list[float],
    lows: list[float],
    closes: list[float],
    *,
    width: int = 1000,
    height: int = 480,
    x_label: str = "",
    y_label: str = "",
    color_up: int = 0x22c55e,
    color_down: int = 0xef4444,
    background: str | None = None,
    gridlines: bool = True,
    hover_json: str | None = None,
) -> Chart

Aliases: sp.candlestick


Description

Financial candlestick chart for OHLC (Open / High / Low / Close) price data.

Green candles indicate a price rise (close > open), red candles a fall.


Parameters

ParameterTypeDefaultDescription
titlestrrequiredChart title
dateslist[str]requiredDate/time labels for X-axis
openslist[float]requiredOpening prices
highslist[float]requiredSession high prices
lowslist[float]requiredSession low prices
closeslist[float]requiredClosing prices
color_upint0x22c55eBullish candle fill color
color_downint0xef4444Bearish candle fill color
widthint1000Canvas width
heightint480Canvas height
y_labelstr""Y-axis label
gridlinesboolTrueHorizontal gridlines
hover_jsonstr | NoneNoneCustom hover JSON

Returns

Chart


Examples

Stock price chart

import seraplot as sp
chart = sp.build_candlestick(
    "AAPL - January 2024",
    ["Jan 2","Jan 3","Jan 4","Jan 5","Jan 8","Jan 9","Jan 10"],
    [185.0, 184.2, 182.5, 181.0, 183.5, 185.0, 186.0],
    [186.5, 185.0, 183.8, 183.5, 186.0, 187.2, 188.0],
    [183.5, 182.0, 180.5, 180.0, 183.0, 184.5, 185.5],
    [184.2, 182.5, 181.0, 183.5, 185.0, 186.0, 187.5],
    y_label="Price ($)",
)
const sp = require('seraplot');
const chart = sp.build_candlestick("AAPL - January 2024",
["Jan 2", "Jan 3", "Jan 4", "Jan 5", "Jan 8", "Jan 9", "Jan 10"],
[185.0, 184.2, 182.5, 181.0, 183.5, 185.0, 186.0],
[186.5, 185.0, 183.8, 183.5, 186.0, 187.2, 188.0],
[183.5, 182.0, 180.5, 180.0, 183.0, 184.5, 185.5],
[184.2, 182.5, 181.0, 183.5, 185.0, 186.0, 187.5],
{
    y_label: "Price ($)"
})
import * as sp from 'seraplot';
const chart = sp.build_candlestick("AAPL - January 2024",
["Jan 2", "Jan 3", "Jan 4", "Jan 5", "Jan 8", "Jan 9", "Jan 10"],
[185.0, 184.2, 182.5, 181.0, 183.5, 185.0, 186.0],
[186.5, 185.0, 183.8, 183.5, 186.0, 187.2, 188.0],
[183.5, 182.0, 180.5, 180.0, 183.0, 184.5, 185.5],
[184.2, 182.5, 181.0, 183.5, 185.0, 186.0, 187.5],
{
    y_label: "Price ($)"
})
▶ Live Preview

See also

Signature

sp.build_candlestick(
    title: str,
    dates: list[str],
    opens: list[float],
    highs: list[float],
    lows: list[float],
    closes: list[float],
    *,
    width: int = 1000,
    height: int = 480,
    x_label: str = "",
    y_label: str = "",
    color_up: int = 0x22c55e,
    color_down: int = 0xef4444,
    background: str | None = None,
    gridlines: bool = True,
    hover_json: str | None = None,
) -> Chart

Aliases: sp.candlestick


Description

Graphique bougie financier pour données OHLC (Ouverture / Haut / Bas / Fermeture). Bougies vertes = hausse (clôture > ouverture), bougies rouges = baisse.


Paramètres

ParamètreTypeDéfautDescription
titlestrrequisTitre du graphique
dateslist[str]requisÉtiquettes dates/heures pour l'axe X
openslist[float]requisPrix d'ouverture
highslist[float]requisPrix hauts de séance
lowslist[float]requisPrix bas de séance
closeslist[float]requisPrix de clôture
color_upint0x22c55eCouleur de la bougie haussiere
color_downint0xef4444Couleur de la bougie baissière
widthint1000Largeur du canvas
heightint480Hauteur du canvas
y_labelstr""Étiquette de l'axe Y
gridlinesboolTrueLignes de grille horizontales
hover_jsonstr | NoneNoneJSON d'infobulle personnalisée

Retourne

Chart


Exemples

import seraplot as sp

chart = sp.build_candlestick(
    "AAPL - Janvier 2024",
    ["2 jan","3 jan","4 jan","5 jan","8 jan","9 jan","10 jan"],
    [185.0, 184.2, 182.5, 181.0, 183.5, 185.0, 186.0],
    [186.5, 185.0, 183.8, 183.5, 186.0, 187.2, 188.0],
    [183.5, 182.0, 180.5, 180.0, 183.0, 184.5, 185.5],
    [184.2, 182.5, 181.0, 183.5, 185.0, 186.0, 187.5],
    y_label="Prix ($)",
)

Voir aussi