情节包括x轴中数据中缺少的日期

发布于 2025-01-26 04:27:07 字数 897 浏览 1 评论 0原文

拥有财务数据,周末/银行假期等没有数据。在下面的示例中,我使用此数据集

假设具有dateFrame,其中索引由时间戳组成,然后天真地使用:

import pandas as pd

pd.options.plotting.backend = "plotly"

fig = df["open"].plot()

返回:

很棒……除了连接丢失数据的直线。添加:

fig.update_layout(xaxis=dict(type="category"))

几乎是完美的:

”在此处输入图像描述”

我现在如何获得相同的脚注(年,每天,每天没有时间)?一旦将索引视为类别,我就可以无法使用%b和CO的日期格式。

Having financial data, there is no data over weekends/bank holidays/etc. In the example below I used this data set.

Assume having a dateframe where the index consists of timestamps then naively plotting the data using:

import pandas as pd

pd.options.plotting.backend = "plotly"

fig = df["open"].plot()

returns:

enter image description here

which is great... except the straight lines connecting the missing data. Adding:

fig.update_layout(xaxis=dict(type="category"))

Is almost perfect:

enter image description here

How can I now get the same tickers (Year, Month, day without the hours)? Once the index is treated as a category then I cannot use date formatter like %b and co.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文