Plotly生成主图表后出现迷你副图,如何去除该底部副图?
解决Plotly图表底部自动显示迷你图表的问题
嘿,那个底部的迷你图表其实是Plotly默认开启的范围滑块(Range Slider),设计初衷是方便快速缩放时间轴类的数据,但确实在不需要的时候会显得很困扰。要去掉它非常简单,只需要在布局配置里关闭这个功能就行。
具体修改步骤:
在你调用py.offline.plot()之前,添加一行代码来关闭范围滑块的显示:
fig.update_layout(xaxis_rangeslider_visible=False)
修改后的完整代码:
import plotly.graph_objects as go from plotly import tools import plotly.offline as py # 假设你的df数据已经准备好 ohlcv = go.Candlestick(x=df.index, open=df.Open, high=df.High, low=df.Low, close=df.Close, name='Currency Quote') rolling_mean = go.Scatter(x=df.index, y=df.Rolling_Mean) boll_upper = go.Scatter(x=df.index, y=df.Upper_Bollinger) boll_lower = go.Scatter(x=df.index, y=df.Lower_Bollinger) fig = tools.make_subplots(rows=1, cols=1, shared_xaxes=True) fig.append_trace(ohlcv, 1, 1) fig.append_trace(rolling_mean, 1, 1) fig.append_trace(boll_upper, 1, 1) fig.append_trace(boll_lower, 1, 1) # 关键:关闭底部的范围滑块 fig.update_layout(xaxis_rangeslider_visible=False) py.offline.plot(fig, filename='CandleStick.html')
补充说明:
如果你之后又需要这个滑块功能,只需要把xaxis_rangeslider_visible的值改成True就可以恢复了。另外,如果你想自定义滑块的样式(比如颜色、高度),也可以通过xaxis_rangeslider的其他参数来配置,不过关闭它是最直接解决你当前问题的方式。
内容的提问来源于stack exchange,提问作者edb500
相关产品推荐
相关产品推荐

