堆叠时间序列图python

问题描述 投票:1回答:1

我想把 SST 和 NickSST 的时间序列叠加在一个图上。当我尝试简单地做,我得到这个错误。

ValueError: x and y must have same first dimension, but have shapes (31,) and (0,).

import datetime
import matplotlib.pyplot as plt

class buoy(object):
    def __init__(self, bID):
        self.buoyID = bID
        self.dateTime = []
        self.SST = []
        self.NickSST = []

    def plotSST(self, stID):
        plotName = stID + "-" + self.buoyID
        self.fig1 = plt.figure()
        plt.ion()
        self.axis1 = self.fig1.add_subplot(1, 1, 1)
        self.axis1.plot(self.dateTime, self.SST)
        self.axis1.plot(self.dateTime, self.NickSST)
        self.axis1.set_title("Time Series for" + "" + plotName)
        self.axis1.set_xlabel("Date/Time (UTC)")
        self.axis1.set_ylabel("SST (degrees C)")
        self.fig1.savefig(plotName + ".png")
        plt.show(self.fig1)

class storm(object):
    def __init__(self, stID):
        self.stormID = stID
        self.buoyList = []

请告诉我,我是怎么错的... ...

python stacked-chart
1个回答
0
投票

看起来你在两个维度上都没有数据。self.SSTself.NickSST.

Matplotlib希望当你调用 plot(x, y)

这个错误告诉你,你的X轴有31个值,而你的Y轴却没有任何值。

print(len(self.dataTime), len(self.SST), len(self.NickSST))
© www.soinside.com 2019 - 2024. All rights reserved.