Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Plotly · Class

go.Ohlc

go.Ohlc creates an interactive financial trace for open, high, low, and close values at each x coordinate. It is commonly used with time-series data to visualize price movement.

How it works

go.Ohlc constructs an OHLC financial trace from coordinates and four price series. Each observation uses the high and low values for the vertical range, while open and close determine the horizontal marks; the trace can then be placed in a Figure and rendered interactively.

Syntax

go.Ohlc(x=..., open=..., high=..., low=..., close=..., increasing_line_color=..., decreasing_line_color=...)

Parameters

NameTypeDescription
xarray-likeCoordinates for the observations, commonly dates or times.
openarray-likeOpening price for each observation.
higharray-likeHighest price for each observation.
lowarray-likeLowest price for each observation.
closearray-likeClosing price for each observation.
increasing_line_colorcolorColor for the line associated with increasing observations.
decreasing_line_colorcolorColor for the line associated with decreasing observations.

Returns

A Plotly OHLC trace object that can be supplied to a Figure.

Key points

  • Each OHLC observation uses horizontal segments to mark its opening and closing prices.
  • The vertical line endpoints identify the low and high prices for each observation.
  • An observation is classified as increasing when close is above open and decreasing when close is below open.

Common mistakes

  • Supply all four price series—open, high, low, and close—because the trace represents each of these values.

Example: Minimal OHLC chart

import plotly.graph_objects as go

fig = go.Figure(go.Ohlc(
    x=["2024-01-01", "2024-01-02"],
    open=[100, 103],
    high=[105, 106],
    low=[98, 101],
    close=[103, 102],
))
fig.show()

Creates and displays an interactive OHLC chart from two time-indexed observations.

When to use it

Financial time series

Visualize price movement across dated observations.

Market-range analysis

Compare opening and closing prices with intraperiod extremes.

Interactive reporting

Embed an interactive chart in a notebook or Plotly application.

Interview questions

QWhat does an OHLC trace encode?

go.Ohlc represents open, high, low, and close values at each x coordinate. The high and low form the vertical range, while horizontal segments indicate open and close.

Follow-up: How would you represent an observation where the close is above the open? It is an increasing item and receives the increasing styling, green by default.

QWhich inputs are needed to create an OHLC chart?

Use x for the observation coordinates and provide matching open, high, low, and close sequences. For financial data, time values are the usual x coordinates.

Follow-up: What happens if x contains ISO date strings? Plotly can infer a date axis from ISO-formatted dates.

QHow is the trace rendered and customized?

Add the trace to a go.Figure, then call fig.show() to render the interactive chart. Styling can be customized, including separate colors for increasing and decreasing observations.

Follow-up: How can the chart be made clearer for a specific dataset? Set explicit increasing and decreasing line colors rather than relying on defaults.

  • go.Candlestick
  • go.Figure
  • plotly.graph_objects

Source: OHLC Charts in Python - Plotly. Checked 2026-10-15.