带有两个刻度的循环子图不起作用

时间:2016-11-24 18:09:29

标签: python matplotlib plot axes multiple-axes

使用Python,我尝试创建一个具有一个x轴和两个y轴的图。这不是问题,但在循环期间仅显示主图中的曲线和par曲线中的最后一条曲线。以下是我的代码。

files = ['File-01', 'File-02', 'File-03']
p = [None]*len(files)
d = [None]*len(files)   

for i in xrange(len(files)):
    p[i] = Read(files[i])
    d[i] = Process(p[i])
    d[i].PlotI()

#some other coding

def PlotI(self):        
    plt.figure('ParameterA and parameterB vs time')
    host = plt.subplot()
    par = host.twinx()
    host.plot(self.time, self.A, label = self.file,
              c = self.colour, linewidth =2, linestyle = '-')
    par.plot(self.time_hrs, self.B, label = self.file,
             c = self.colour, linewidth = 2, linestyle = ':')
    host.set_xlabel('Time [-]')
    host.set_ylabel('A [-]')
    par.set_ylabel('B [-]')
    plt.legend(loc = 'best', frameon=0)

所以我尝试做的是,在同一个图中绘制n个不同的文件参数A和B(两个向量)。共享x轴的位置,两个参数都有自己的y轴 希望你能帮助我!

0 个答案:

没有答案