Financial time series
Visualize price movement across dated observations.
Plotly · Class
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.
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.
go.Ohlc(x=..., open=..., high=..., low=..., close=..., increasing_line_color=..., decreasing_line_color=...)| Name | Type | Description |
|---|---|---|
x | array-like | Coordinates for the observations, commonly dates or times. |
open | array-like | Opening price for each observation. |
high | array-like | Highest price for each observation. |
low | array-like | Lowest price for each observation. |
close | array-like | Closing price for each observation. |
increasing_line_color | color | Color for the line associated with increasing observations. |
decreasing_line_color | color | Color for the line associated with decreasing observations. |
A Plotly OHLC trace object that can be supplied to a Figure.
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.
Visualize price movement across dated observations.
Compare opening and closing prices with intraperiod extremes.
Embed an interactive chart in a notebook or Plotly application.
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.
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.
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.Candlestickgo.Figureplotly.graph_objects