GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • PYTHON CHARTS
  • matplotlib
  • seaborn
  • plotly
  • pandas
  • colors
  • COLORS
  • COLOR PALETTES
  • R CODER
  • R CHARTS
  • Contact
  • Español

This view

  • Original page
  • New address

GeezerVison is showing python-charts.com — Candlestick chart in plotly

Search for a graph

HOME EVOLUTION CANDLESTICK CHART PLOTLY

Candlestick chart in plotly

Candlestick chart in plotly with Candlestick

A candlestick chart displays the open, high, low and close price (OHLC) of an asset for each period, which is why it is mostly used for financial data. Use the Candlestick class from plotly.graph_objects, passing an array of dates to x and the four price series to open, high, low and close.

import plotly.graph_objects as go
import pandas as pd

# Sample data
dates = pd.date_range("2024-01-01", periods = 10, freq = "D")
open_p = [100, 102, 101, 104, 103, 105, 107, 106, 108, 110]
high_p = [103, 104, 105, 106, 106, 108, 109, 109, 111, 113]
low_p = [99, 100, 100, 102, 101, 104, 105, 104, 107, 108]
close_p = [102, 101, 104, 103, 105, 107, 106, 108, 110, 109]

fig = go.Figure(data = [go.Candlestick(
    x = dates, open = open_p, high = high_p, low = low_p, close = close_p)])

fig.show()

Colors

The color of the rising and falling candles is set independently through the increasing and decreasing arguments, each accepting a dict with a line_color key (and optionally fillcolor).

import plotly.graph_objects as go
import pandas as pd

# Sample data
dates = pd.date_range("2024-01-01", periods = 10, freq = "D")
open_p = [100, 102, 101, 104, 103, 105, 107, 106, 108, 110]
high_p = [103, 104, 105, 106, 106, 108, 109, 109, 111, 113]
low_p = [99, 100, 100, 102, 101, 104, 105, 104, 107, 108]
close_p = [102, 101, 104, 103, 105, 107, 106, 108, 110, 109]

fig = go.Figure(data = [go.Candlestick(
    x = dates, open = open_p, high = high_p, low = low_p, close = close_p,
    increasing_line_color = "#55A868", decreasing_line_color = "#C44E52")])

fig.show()

Removing the range slider

By default plotly adds a range slider below the chart. Remove it by setting xaxis_rangeslider_visible to False with update_layout.

import plotly.graph_objects as go
import pandas as pd

# Sample data
dates = pd.date_range("2024-01-01", periods = 10, freq = "D")
open_p = [100, 102, 101, 104, 103, 105, 107, 106, 108, 110]
high_p = [103, 104, 105, 106, 106, 108, 109, 109, 111, 113]
low_p = [99, 100, 100, 102, 101, 104, 105, 104, 107, 108]
close_p = [102, 101, 104, 103, 105, 107, 106, 108, 110, 109]

fig = go.Figure(data = [go.Candlestick(
    x = dates, open = open_p, high = high_p, low = low_p, close = close_p)])
fig = fig.update_layout(xaxis_rangeslider_visible = False)

fig.show()

Title

Add a title the same way as in any other plotly figure, with update_layout.

import plotly.graph_objects as go
import pandas as pd

# Sample data
dates = pd.date_range("2024-01-01", periods = 10, freq = "D")
open_p = [100, 102, 101, 104, 103, 105, 107, 106, 108, 110]
high_p = [103, 104, 105, 106, 106, 108, 109, 109, 111, 113]
low_p = [99, 100, 100, 102, 101, 104, 105, 104, 107, 108]
close_p = [102, 101, 104, 103, 105, 107, 106, 108, 110, 109]

fig = go.Figure(data = [go.Candlestick(
    x = dates, open = open_p, high = high_p, low = low_p, close = close_p)])
fig = fig.update_layout(title = "Stock price", xaxis_rangeslider_visible = False)

fig.show()

Hiding weekend gaps

With daily stock data, weekends have no trading and create empty gaps on the X-axis. Remove them by adding a rangebreak for Saturdays and Sundays.

import plotly.graph_objects as go
import pandas as pd

# Sample data (business days only)
dates = pd.bdate_range("2024-01-01", periods = 10)
open_p = [100, 102, 101, 104, 103, 105, 107, 106, 108, 110]
high_p = [103, 104, 105, 106, 106, 108, 109, 109, 111, 113]
low_p = [99, 100, 100, 102, 101, 104, 105, 104, 107, 108]
close_p = [102, 101, 104, 103, 105, 107, 106, 108, 110, 109]

fig = go.Figure(data = [go.Candlestick(
    x = dates, open = open_p, high = high_p, low = low_p, close = close_p)])
fig = fig.update_xaxes(rangebreaks = [dict(bounds = ["sat", "mon"])])

fig.show()
R CODER website
Storytelling with Data

Storytelling with Data

A Data Visualization Guide for Business Professionals

Buy on Amazon
Fundamentals of Data Visualization

Fundamentals of Data Visualization

A Primer on Making Informative and Compelling Figures

Buy on Amazon

See also

Area chart in pandas

Area chart in pandas

Area chart in seaborn

Area chart in seaborn

Line plot in matplotlib

Line plot in matplotlib

Streamgraph in matplotlib

Streamgraph in matplotlib

Candlestick chart in Python with mplfinance

Candlestick chart in Python with mplfinance

Step plot in matplotlib

Step plot in matplotlib

Line chart in seaborn with lineplot

Line chart in seaborn with lineplot

Area plot in matplotlib with fill_between

Area plot in matplotlib with fill_between

Stacked area plot in matplotlib with stackplot

Stacked area plot in matplotlib with stackplot

Gantt chart in plotly

Gantt chart in plotly

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.