@@ -0,0 +1,2084 @@
+# -*- coding:utf-8 -*-%0A%22%22%22%0A========================================================================%0AProvide pure data file class which do operations on these files.%0A========================================================================%0AWritten by PytLab %3Cshaozhengjiang@gmail.com%3E, September 2015%0AUpdated by PytLab %3Cshaozhengjiang@gmail.com%3E, September 2015%0A========================================================================%0A%0A%22%22%22%0Aimport numpy as np%0Aimport matplotlib.pyplot as plt%0A%0Afrom functions import line2list%0A%0A%0Aclass DataPlotter(object):%0A    def __init__(self, filename, field=' ', dtype=float):%0A        self.filename = filename%0A        self.field = field%0A        self.dtype = dtype%0A        #load data%0A        self.load()%0A%0A    def load(self):%0A        %22Load all data in file into array.%22%0A        data = %5B%5D%0A        with open(self.filename, 'r') as f:%0A            for line in f:%0A                line = line.strip()%0A                if not line%5B0%5D.isdigit():  # comment line or not%0A                    continue%0A                linedata = line2list(line, field=self.field,%0A                                     dtype=self.dtype)%0A                data.append(linedata)%0A        self.data = np.array(data)%0A%0A        return data%0A%0A    def plot2d(self, xcol, ycols):%0A        %22%E6%98%BE%E7%A4%BA%E7%89%B9%E5%AE%9A%E4%B8%A4%E5%88%97%E6%95%B0%E6%8D%AE%22%0A        '''%0A        Parameter%0A        ---------%0A        xcol: int%0A            column number of data for x values%0A        ycols: tuple of int%0A            column numbers of data for y values%0A            (start, stop%5B, step%5D)%0A        Example:%0A        %3E%3E%3E a.plot2d(0, (1, 3, 1))%0A        '''%0A        x = self.data%5B:, xcol%5D%0A        fig = plt.figure()%0A        ax = fig.add_subplot(111)%0A        for i in xrange(*ycols):%0A            y = self.data%5B:, i%5D%0A            ax.plot(x, y, linewidth=3)%0A%0A        fig.show()%0A%0A    def plotall(self):%0A        %22%E5%B0%86%E6%89%80%E6%9C%89%E6%95%B0%E6%8D%AE%E4%B8%80%E8%B5%B7%E6%98%BE%E7%A4%BA%22%0A        ncols = self.data.shape%5B1%5D%0A        x = self.data%5B:, 0%5D%0A        fig = plt.figure()%0A        ax = fig.add_subplot(111)%0A        for col in xrange(1, ncols):%0A            y = self.data%5B:, col%5D%0A            ax.plot(x, y, linewidth=3)%0A        fig.show()%0A

add DataPlotter class