日期中不需要的堆叠数据\u p

2024-04-20 10:10:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试显示曲线。脓肿是日期,纵坐标是双值(在本例中为幂)。 数据提供的日期不相同。但当两个日期匹配时,添加的第二组数据将叠加在前一组数据上

示例1:FR添加在DE之后,数据量减少4倍 Example 1: FR is added after DE and has 4 times less data

示例2:DE添加在FR之后,数据量增加了4倍。 Example 2: DE is added after FR and has 4 times more data.

我当前运行的代码是:

    # Clean figure
    fig = plt.figure()

    for country in ['DE', 'FR']:

        production = getProduction(
            country=country,
            start=start,
            end=end,
            session=session,
            verbose=False,
            debug=False)

        allTimeseries = production['all']['timeseries']

        print(allTimeseries)

        timestamps = []
        values = []
        for date in allTimeseries.keys():
            timestamps.append(date)
            values.append(allTimeseries[date]['power']['quantity'])

        # Add the plot to the figure
        plt.plot_date(timestamps, values, label=country, antialiased=True)

    plt.xticks(rotation=30, ha="right")
    plt.legend(loc='upper left', ncol=1)

    # plt.show()
    plt.tight_layout()
    plt.savefig('test.png', dpi=fig.dpi)

如何防止两个系列堆叠


Tags: 数据in示例fordatefigdeplt