以下代码使用范围滑块绘制蜡烛图。如果我将滑块缩小,我希望在垂直比例尺上进行缩放。如何实现这一点?我期望有某种设置可以做到这一点,但我找不到它。目前的结果可能看起来像屏幕截图;显然不是最佳的。大部分垂直比例尺仍未被使用。如何解决这个问题?
import sys
import pandas as pd
import plotly.graph_objects as go
from datetime import datetime
from Downloader import CDownloader
# import matplotlib.dates as mdates # Styling dates
class CGraphs:
def Candlestick(self, aSymbolName:str):
# Warning, this function reads from disk, so it is slow.
print(sys._getframe().f_code.co_name, ": Started. aSymbolName ", aSymbolName)
downloader : CDownloader = CDownloader()
df_ohlc : pd.DataFrame = downloader.GetHistoricalData(aSymbolName)
print("df_ohlc", df_ohlc)
graph_candlestick = go.Figure()
candle = go.Candlestick(x = df_ohlc['Date'],
open = df_ohlc['Open'],
high = df_ohlc['High'],
low = df_ohlc['Low'],
close = df_ohlc['Close'],
name = "Candlestick " + aSymbolName)
graph_candlestick.add_trace(candle)
graph_candlestick.update_xaxes(title="Date", rangeslider_visible=True)
graph_candlestick.update_yaxes(title="Price", autorange=True)
graph_candlestick.update_layout(
title = aSymbolName,
height = 600,
width = 900,
showlegend = True)
graph_candlestick.update_layout(xaxis_rangebreaks = [ dict(bounds=["sat", "mon"]) ])
graph_candlestick.show()
print(sys._getframe().f_code.co_name, ": Finished. aSymbolName ", aSymbolName)
graphs:CGraphs = CGraphs()
graphs.Candlestick("MSFT")