.Ohlc()
Published Mar 16, 2025
Contribute to Docs
In Plotly, the .Ohlc()
function is used to create an OHLC (Open-High-Low-Close) chart, which is commonly used in financial analysis to represent stock price movements over time. Each data point in an OHLC chart consists of four values:
- Open: The price at which the asset opened.
- High: The highest price recorded during the time period.
- Low: The lowest price recorded during the time period.
- Close: The price at which the asset closed.
These charts are useful for traders and analysts to identify trends and price movements.
Syntax
plotly.graph_objects.Ohlc(x=None, open=None, high=None, low=None, close=None, ...)
x
: A list of date/time values for each data point.open
: A list of opening prices.high
: A list of highest prices.low
: A list of lowest prices.close
: A list of closing prices.
Note: The ellipsis (…) in the syntax indicates that there can be additional optional parameters beyond those listed here.
Example
The following example demonstrates the usage of the .Ohlc()
function:
import plotly.graph_objects as go# Sample datadates = ["2024-03-10", "2024-03-11", "2024-03-12", "2024-03-13", "2024-03-14"]opens = [100, 102, 105, 107, 110]highs = [105, 108, 110, 112, 115]lows = [98, 100, 103, 105, 108]closes = [102, 106, 108, 110, 113]# Create an OHLC chartfig = go.Figure(data=[go.Ohlc(x=dates,open=opens,high=highs,low=lows,close=closes)])# Update the chart with labelsfig.update_layout(title="OHLC Chart", xaxis_title="Date", yaxis_title="Price")# Display the chartfig.show()
The above code generates the following output:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:Plotly on Codecademy
- Career path
Data Scientist: Machine Learning Specialist
Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.Includes 27 CoursesWith Professional CertificationBeginner Friendly95 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours