I used make_subplots of plotly for generating multiple candle graphs, but graphs were collapsed by x-range slider. I would like to know:
- How to get rid of ALL x-range slider. My implementation still yields x-range slide although
fig.update_layout(xaxis_rangeslider_visible=False)is in it. - How to make not-collapsed graphs with x-range slider. If you comment out
fig.update_layout(xaxis_rangeslider_visible=False), you can find x-range slider destroy a graph above.
Please execute test_candle(graph_type="candle") for reprodicing collapsed graph.
test_candle(graph_type="line") will show you not-collapsed example(and not-candle type).
def test_candle(graph_type="candle"):
import pandas as pd
import plotly.offline as offline
import plotly.graph_objs as go
from plotly.subplots import make_subplots
col_N = 3 # max columns
N = 7 # a number of graphs
# sample data
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
# calculate a (row, col) coordinate of the x-th graph.
func = lambda x : ((x + (col_N-1)) // col_N, (x - 1) % col_N + 1)
fig = make_subplots(
rows=N // col_N + N % col_N,
cols=col_N,
subplot_titles=[f"graph {i}" for i in range(1, N+1)]
)
row0, col0 = func(N)
fig.update_layout(width = 1000*col_N)
fig.update_layout(height = 1000*row0)
fig.update_layout(xaxis_rangeslider_visible=False)
for i in range(1, N+1):
if graph_type == "candle":
graph = go.Candlestick(
x=df["Date"],
open=df["AAPL.Open"],
high=df["AAPL.High"],
low=df["AAPL.Low"],
close=df["AAPL.Close"]
)
elif graph_type == "line":
graph = go.Line(x=df["Date"],y=df["AAPL.Close"])
else:
raise ValueError("Invalid graph type : {}".format(graph_type))
row1, col1 = func(i)
fig.add_trace(graph, row=row1, col=col1)
offline.plot(fig, filename = 'sample-candle.html', auto_open=True)