hvPlot.ohlc#

hvPlot.ohlc(x=None, y=None, **kwds)[source]#

The ohlc plot visualizes the open, high, low and close prices of stocks and other assets.

Reference: https://hvplot.holoviz.org/ref/api/manual/hvplot.hvPlot.ohlc.html

Plotting options: https://hvplot.holoviz.org/ref/plotting_options/index.html

Parameters:
xstring, optional

Field name to draw x coordinates from. If not specified, the index is used. Normally refers to date values.

ylist or tuple, optional

Field names of the OHLC fields. Default is [“open”, “high”, “low”, “close”]

bar_width: number, optional

Bar width. Default is 0.5.

line_colorstring, optional

The line color. Default is black

pos_colorstring, optional

The color indicating a positive change. Default is green.

neg_colorstring, optional

The color indicating a negative change. Default is red.

**kwdsoptional

Additional keywords arguments are documented in Plotting Options. Run hvplot.help('ohlc') for the full method documentation.

Returns:
holoviews.element.Rectangles / Panel object

You can print the object to study its composition and run:

import holoviews as hv
hv.help(the_holoviews_object)

to learn more about its parameters and options.

References

Backend-specific styling options#

alpha, cmap, color, fill_alpha, fill_color, hover_alpha, hover_color, hover_fill_alpha, hover_fill_color, hover_line_alpha, hover_line_cap, hover_line_color, hover_line_dash, hover_line_dash_offset, hover_line_join, hover_line_width, line_alpha, line_cap, line_color, line_dash, line_dash_offset, line_join, line_width, muted, muted_alpha, muted_color, muted_fill_alpha, muted_fill_color, muted_line_alpha, muted_line_cap, muted_line_color, muted_line_dash, muted_line_dash_offset, muted_line_join, muted_line_width, nonselection_alpha, nonselection_color, nonselection_fill_alpha, nonselection_fill_color, nonselection_line_alpha, nonselection_line_cap, nonselection_line_color, nonselection_line_dash, nonselection_line_dash_offset, nonselection_line_join, nonselection_line_width, selection_alpha, selection_color, selection_fill_alpha, selection_fill_color, selection_line_alpha, selection_line_cap, selection_line_color, selection_line_dash, selection_line_dash_offset, selection_line_join, selection_line_width, visible

alpha, c, capstyle, cmap, color, ec, ecolor, edgecolor, facecolor, fc, fill, hatch, joinstyle, linestyle, linewidth, lw

Examples#

This example shows how to create a simple candlestick-style ohlc plot with a dummy dataset.

import hvplot.pandas  # noqa
import pandas as pd

df = pd.DataFrame({
    "open": [100, 101, 102],
    "high": [104, 105, 110],
    "low": [94, 97, 99],
    "close": [101, 99, 103],
}, index=pd.date_range("2024-01-01", periods=3, freq="1D"))

df.hvplot.ohlc()

Let’s use some a more realistic dataset.

import hvplot.pandas  # noqa

df = hvplot.sampledata.apple_stocks("pandas").set_index("date").loc["2024-04", :].reset_index()

df.hvplot.ohlc(ylabel="Stock price")

We can also plot with the index as the date.

import hvplot.pandas  # noqa

df = hvplot.sampledata.apple_stocks("pandas").set_index("date").loc["2024-04", :]

df.hvplot.ohlc(ylabel="Stock price")

We can control the plot styling with neg_color, pos_color, line_color and bar_width:

import hvplot.pandas  # noqa

df = hvplot.sampledata.apple_stocks("pandas").set_index("date").loc["2024-04", :]

df.hvplot.ohlc(
    neg_color='indianred', pos_color='chartreuse',
    line_color='gray', bar_width=0.9,
)

By default ohlc will assume the index OR the first datetime column should be mapped to the x-axis and the first four non-datetime columns correspond to the O (open), H (high), L (low) and C (close) components. The default call is therefore equivalent to:

import hvplot.pandas  # noqa

df = hvplot.sampledata.apple_stocks("pandas").set_index("date").loc["2024-04", :].reset_index()

df.hvplot.ohlc(x='date', y=['open', 'low', 'high', 'close'])
This web page was generated from a Jupyter notebook and not all interactivity will work on this website.