【问题标题】:Display only data on axis that is present in the figure仅显示图中存在的轴上的数据
【发布时间】:2020-10-19 23:05:47
【问题描述】:

如何隐藏未使用的 32.Jun, 14 2020 代码。它们在我提供的数据中不存在。

我正在设置这样的定位器:

plt.gca().xaxis.set_major_locator(DayLocator())
plt.gca().yaxis.set_major_locator(MultipleLocator(1))

【问题讨论】:

    标签: python datetime matplotlib formatting xticks


    【解决方案1】:

    对于 y 轴,您应该使用:

    plt.gca().set_ylim([27, 31])
    

    x 轴也一样,但您应该使用日期格式。你能提供你做情节的代码行吗? 例如,如果您的 x 轴数据位于 'Date' 数据框的 'Date' 列中,您可以使用:

    plt.gca().set_xlim([df['Date'].iloc[0], df['Date'].iloc[-1]])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-08
      • 1970-01-01
      • 1970-01-01
      • 2019-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多