【问题标题】:matplotlib plot_dates break the line when yaxis integer change length [duplicate]当y轴整数改变长度时,matplotlib plot_date断线[重复]
【发布时间】:2019-02-22 08:41:18
【问题描述】:

所以我有一个 data:number 匹配列表。 我将每个列表的长度更改为 32~。 比我画的:

    list_of_datetimes = [s for (i, s) in enumerate(list_of_datetimes) if (i % (len(list_of_datetimes) >> 5)) == 0]
    y_axis = [s for (i, s) in enumerate(y_axis) if (i % (len(y_axis) >> 5)) == 0]

    dates = mdates.datestr2num(list_of_datetimes)
    plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%d/%m/%Y'))
    #plt.gca().xaxis.set_major_locator(mdates.DayLocator())
    plt.style.use('seaborn-whitegrid')
    plt.gcf().autofmt_xdate()
    plt.plot_date(dates, y_axis, linestyle='solid', marker='None')

而且我不明白为什么图表会中断: chart_breaks

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    这是因为您的 y 轴是按字母顺序排列的,而不是从小到大。

    将绘制在 y 轴上的类型更改为 floatint,它应该可以工作:

    y_axis = [float(s) for (i, s) in enumerate(y_axis) if (i % (len(y_axis) >> 5)) == 0]
    

    【讨论】:

    • 工作!谢谢。 (我不敢相信我在网上一无所获)
    猜你喜欢
    • 1970-01-01
    • 2011-03-29
    • 2020-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多