由于我必须创建相当多的图形,所以我决定创建一个类,在其中我编写了一个函数,该函数填充了几个图形。此图表最多可包含一个数据集。我尝试过这样做,尝试除了'但是,我的图表只显示我传入的最后一个数据集,我做错了什么?
class Graf(object):
def __init__(self, x, x2, x3, x4, y, version):
self.s = 0
self.x = x
self.x2 = x2
self.x3 = x3
self.x4 = x4
self.y = y
if version == 1:
#Define xlabels, ylabels, titles etc.
elif version == 2:
#etc
elif version == 3:
#etc
def Plot(self):
#plot labels, titles etc
#First dataset for graph
plt.plot(self.y,self.x,'b', label = self.label1)
try: #Try to add second dataset if it is available
plt.plot(self.y,self.x2,'r', label = self.label2)
except AttributeError:
pass
#This piece of code is repeated 2 times (with x3 and x4)
这是我的主要代码片段,请原谅我的代码的荷兰语部分
if __name__ == "__main__":
Isolatie = Lijst(9,myGUI)
Isolatie.Isolatie()
Uitstroomtemp = Graf(Isolatie.t_iso, Isolatie.t_iso, 0, 0, Isolatie.massa_water, 1)
Uitstroomtemp.Plot()
我试图只发布我的代码的相关部分,对不起,如果它有点乱,不是Pythonic或代码的相关部分不包括在内。请让我知道,我试图抓住Python。