【问题标题】:Python & Matplotlib - Creating date ticks from stringPython & Matplotlib - 从字符串创建日期刻度
【发布时间】:2011-03-26 01:16:37
【问题描述】:

我有一个字符串数组,其中包含格式如下的日期:'01/01/09'。我还有一个带有日期值的浮点数组。

我想获取这些日期并最终将它们显示为我的图表上的 x 刻度标签。

如何使用浮点数或字符串在我的 matplotlib 图形的 x 轴上标记刻度? (使用 xticks 之类的东西)

【问题讨论】:

    标签: python datetime matplotlib plot


    【解决方案1】:

    您使用set_xticks 设置刻度的计数(和值)。您使用 set_xticklabels

    设置刻度的文本
    from matplotlib import pyplot as plt
    plt.plot([1,2,3],[3,4,3])
    ax = plt.gca()
    ax.set_xticks([1,2,3])
    ax.set_xticklabels(['1/1','1/2','1/3'])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-16
      • 1970-01-01
      • 1970-01-01
      • 2020-10-01
      • 1970-01-01
      • 2020-02-17
      • 1970-01-01
      相关资源
      最近更新 更多