【问题标题】:How to plot selected rows that are datetime in x axis and another column in y axis如何在 x 轴上绘制日期时间的选定行,在 y 轴上绘制另一列
【发布时间】:2021-08-06 06:54:35
【问题描述】:

我有 3 天的货币兑换数据,间隔为 15 分钟。我将日期列更改为日期时间,在 matplotlib 中绘图时,它给出了 12 小时的 x 轴刻度。如何选择 3 小时的数据并以给定的 15 分钟时间间隔进行绘图?

plt.figure(figsize=(20, 10))
plt.plot(EURJPY['Date'],EURJPY['Close'])
plt.xticks(rotation='vertical')
plt.grid(True)
plt.show()

我也试过这段代码,但它给出的输出是 x 轴值作为行号。

EURJPY.loc[(EURJPY['Date'] > '07/05/2021 07:00') & (EURJPY['Date'] <= '07/05/2021 11:00')].plot(y='Close')

如何选择上午 9 点到下午 1 点的收盘价? 谢谢

【问题讨论】:

    标签: python datetime plot


    【解决方案1】:

    您应该根据最后一个逻辑在第一个 sn-p 中分割您的 xy

    idx = (EURJPY['Date'] > '07/05/2021 07:00') & (EURJPY['Date'] <= '07/05/2021 11:00')
    plt.figure(figsize=(20, 10))
    plt.plot(EURJPY.loc[idx,'Date'],EURJPY.loc[idx,'Close'])
    plt.xticks(rotation='vertical')
    plt.grid(True)
    plt.show()
    

    【讨论】:

    • 成功了。它在 x 轴上显示 30 分钟的时间间隔。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多