matplotlib:为什么日期粘在一起?

carvr3hs  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(318)

我目前正在分析股票。因此,我想根据时间来计算它们的价格。为此,我有以下功能:

def plot_pandas(column,start, end, y_label = 'USD'):
    fig, axes = plt.subplots(nrows=1, ncols = 1)

      # title
    plt.title(column.columns[0])

      # x_axis  
    plt.xlabel('Date', fontsize=18)

    axes.set_xlim(start, end)
    years = mdates.YearLocator()   # every year
    months = mdates.MonthLocator()  # every month
    years_fmt = mdates.DateFormatter('%Y')

    axes.xaxis.set_major_locator(years)
    axes.xaxis.set_major_formatter(years_fmt)
    axes.xaxis.set_minor_locator(months)
    axes.format_xdata = mdates.DateFormatter('%Y-%m')
    fig.autofmt_xdate()

      # y_axis  
    plt.ylabel(column.columns[0] + ' ' + y_label, fontsize=18)

      # frame_size
    fig.set_figheight(8)
    fig.set_figwidth(15)
    plt.figure(figsize=(16,6))
      # data
    plt.plot(column)

    plt.show()

但正如你在图片上看到的:日期是粘在一起的。有人能帮忙吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题