擅长:python、mysql、java
<p>您可以通过plotly中的rangebreaks来实现这一点</p>
<p>下面是在交易时间和周末之外隐藏的代码</p>
<pre class="lang-py prettyprint-override"><code> fig = go.Figure(data=[go.Candlestick(x=df['date'], open=df['Open'], high=df['High'], low=df['Low'], close=df['Close'])])
fig.update_xaxes(
rangeslider_visible=True,
rangebreaks=[
# NOTE: Below values are bound (not single values), ie. hide x to y
dict(bounds=["sat", "mon"]), # hide weekends, eg. hide sat to before mon
dict(bounds=[16, 9.5], pattern="hour"), # hide hours outside of 9.30am-4pm
# dict(values=["2019-12-25", "2020-12-24"]) # hide holidays (Christmas and New Year's, etc)
]
)
fig.update_layout(
title='Stock Analysis',
yaxis_title=f'{symbol} Stock'
)
fig.show()
</code></pre>
<p>这是<a href="https://plotly.com/python/time-series/#hiding-weekends-and-holidays" rel="nofollow noreferrer">Plotly's doc</a></p>