Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Candlestick and volume bar charts are seperate! Can I combine them?

Hello Fam, Python Noob here…

Finally i was able to draw a candlestick Price chart (using plotly.graph_objects) and a Volume Bar Chart (using plotly.express).

Can I plot the charts to be together in one figure? If yes, how? I found this picture online, but i could not replicate it.

If no, how can I link both charts x-axes such that when I zoom on one, the other plots will update?

#import the libraries
import plotly.graph_objects as go
import plotly.express as px
import pandas as pd

#Load the stock data
df = pd.read_csv(‘20180507-table_blnk.csv’)
#Set the index
df = df.set_index(pd.DatetimeIndex(df[‘Time’].values))
#Show the data
df

#Create a Candlestick Price Chart
PriceFigure = go.Figure(
data = [
go.Candlestick(
x = df.index,
low = df[‘Low’],
high = df[‘High’],
close = df[‘Close’],
open = df[‘Open’],
increasing_line_color = ‘green’,
decreasing_line_color = ‘red’
)
]
)
#Create a Volume Bar Chart
VolumeFigure = px.bar(x = df.index, y = df[‘Volume’])

#Update Price Figure layout
PriceFigure.update_layout(
title = ‘PM Breakout’,
yaxis_title = ‘Stock Price ($)’,
xaxis_title = ‘Time’,
xaxis_rangeslider_visible = True
)

#Update Volume Figure Layout
VolumeFigure.update_layout(
title = ‘Volume’,
yaxis_title = ‘Volume (M)’,
xaxis_title = ‘Time’
)

#Draw Figures
PriceFigure.show()
VolumeFigure.show()

subplot with shared x axis ?? OR

#link zoom level on both charts ??