Python

plotly.figure_factory.create_ohlc

In this brief tutorial, we will cover how to create a basic OHLC plot using the Plotly figure_factory module.

Function Syntax and Parameters

The function syntax and parameter list are as shown:

plotly.figure_factory.create_ohlc(open, high, low, close, dates=None, direction=’both’, **kwargs)

The required parameters are as shown:

  1. open – sets the opening values
  2. high – sets the high values
  3. low – defines the low values
  4. close – sets the closing values
  5. dates – a list of datetime objects

OHLC Plot With Figure Factory

The following code illustrates how to create an OHLC Plot using Plotly figure_factory module:

from plotly.figure_factory import create_ohlc

import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')

fig = create_ohlc(df['AAPL.Open'], df['AAPL.High'], df['AAPL.Low'], df['AAPL.Close'], dates=df.index)

fig.show()

The previous code should create an OHLC figure with the provided data as shown below:

To show the RangeSlider, set the parameter layout_xaxis_rangeslider_visible to True as shown:

From plotly.figure_factory, import the create_ohlc:

import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')

fig = create_ohlc(df['AAPL.Open'], df['AAPL.High'], df['AAPL.Low'], df['AAPL.Close'], dates=df.index)

fig.update(layout_xaxis_rangeslider_visible=True)

fig.show()

The resulting figure is shown below:

Conclusion

This article covers the basics of creating OHLC Plots using the Plotly figure_factory module. The OHLC plots pertain to the open-high-low-close data.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list