Ejemplo n.º 1
0
    def plot_var_time(path, var, fig):
        #retrive time data and if not possible just return
        axis = []
        data = []

        timePath = findCorrespondingTime(path)
        if timePath is "":
            return
        time_data = []
        time = combineYMDHMwithSec(timePath)
        for t in time:
            time_data.append(t)
        #retive y-axis data
        y = getDataFromVar(path, var)

        #Create plot
        axis.append(fig.add_subplot(1, 1, 1))
        axis[0].set_title(
            header_info_to_plot(path) + "\n " + "Plot " + name(var) +
            " versus Time ")
        if len(time_data) == len(y):
            #axis[0].xticks(rotation= 80)
            axis[0].plot(time_data, y)
            axis[0].set_xlabel('Time')
            axis[0].set_ylabel(name(var) + unit(var))
            #axis[0].set_xticklabels(axis[0].get_xticklabels(), rotation=80)
            data.append(pd.Series(y, index=time_data))
        else:
            raise ValueError('Time and data do not have same length')
        return axis, data
Ejemplo n.º 2
0
    def append_table(self, paths, vars):
        y = get_data_to_table(paths[-1],vars[-1])
        new_data = {}
        if len(y) == 1 :
            self.data[name(vars[-1])] = y[0]
            new_data[name(vars[-1])] = y[0]

        else:
            for i in range(len(y)):
                self.data[name(vars[-1])+' #'+ str(i+1)] = y[i]
                new_data[name(vars[-1])+' #'+ str(i+1)] = y[i]
        return new_data
Ejemplo n.º 3
0
 def plot_one_var(paths, vars, fig):
     y = getDataFromVar(paths[0], vars[0])
     x = range(1, len(y) + 1)
     axis = []
     data = []
     axis.append(fig.add_subplot(1, 1, 1))
     axis[0].plot(x, y)
     axis[0].set_title(
         header_info_to_plot(paths[0]) + '\n' + 'Plot' + name(vars[0]))
     axis[0].set_xlabel('Index')
     axis[0].set_ylabel(name(vars[0]) + unit(paths[0], vars[0]))
     data.append(pd.Series(y, index=x))
     return axis, data
Ejemplo n.º 4
0
 def tableFunctionGeneral(self,paths,vars):
     self.data_reset()
     timePath = findCorrespondingTime(paths[0].strip())
     if os.path.isfile(timePath):
         time =  combineYMDHMwithSec(timePath)
         self.data[Tablefunction.time_key] = time
     c = 0
     for path in paths:
         y = get_data_to_table(path, vars[c])
         if len(y) == 1 :
             self.data[name(vars[c])] = y[0]
         else:
             for i in range(len(y)):
                 y[i]= np.squeeze(np.asarray(y[i])) # to convert matrix to array if needed
                 self.data[name(vars[c])+'#'+ str(i+1)] = y[i]
         c = c + 1
     return self.data
Ejemplo n.º 5
0
    def plot_two_vars(paths, vars, fig):

        # retrive data to plot
        x = getDataFromVar(paths[0], vars[0])
        y = getDataFromVar(paths[1], vars[1])
        axis = []
        data = []
        #create figure
        axis.append(fig.add_subplot(1, 1, 1))
        axis[0].plot(x, y)
        axis[0].set_title(
            header_info_to_plot(paths[0]) + '\n' + 'Plot' + name(vars[0]) +
            'versus ' + name(vars[1]))
        #ax.plot(x,y)
        axis[0].set_xlabel(name(vars[0]) + unit(paths[0], vars[0]))
        axis[0].set_ylabel(name(vars[1]) + unit(paths[1], vars[1]))
        data.append(pd.Series(y, index=x))
        return axis, data
Ejemplo n.º 6
0
    def plot_two_var_time(paths, vars, fig):

        # Define return arrays'
        axis = []
        data = []

        #try to retrive time data, if can not just return
        timePath = findCorrespondingTime(paths[0])
        time = combineYMDHMwithSec(timePath)
        time_data = []
        i = 0
        for t in time:
            time_data.append(t)
        # retriv y-axis data
        y1 = getDataFromVar(paths[0], vars[0])
        y2 = getDataFromVar(paths[1], vars[1])

        if len(time) == len(y1) and len(time) == len(y2):
            axis.append(fig.add_subplot(1, 1, 1))
            #ax1 = fig.add_subplot(1,1,1)
            color = 'tab:red'
            axis[0].set_xlabel('Time H:M:S')
            axis[0].set_ylabel(name(vars[0]) + unit(paths[0], vars[0]))
            axis[0].plot(time_data, y1, color=color)
            #plt.xticks( rotation= 80 )
            axis[0].tick_params(axis=vars[0], labelcolor=color)
            axis.append(axis[0].twinx(
            ))  # instantiate a second y-axis that shares the same x-axis
            color = 'tab:blue'
            axis[1].plot(time_data, y2, color=color)
            axis[1].set_ylabel(name(vars[1]) + unit(paths[1], vars[1]))
            axis[1].tick_params(axis=vars[1], labelcolor=color)
            plt.title(
                header_info_to_plot(paths[0]) + "\nPlot " + name(vars[0]) +
                "and " + name(vars[1]) + " over time ")
            data.append(pd.Series(y1, index=time_data))
            data.append(pd.Series(y2, index=time_data))
            return axis, data
        else:
            print("Dimensions do not agree")
Ejemplo n.º 7
0
    def plot_three_vars(paths, vars, fig):
        #retrive data
        axis = []
        data = []

        #get data
        x = getDataFromVar(paths[0], vars[0])
        y1 = getDataFromVar(paths[1], vars[1])
        y2 = getDataFromVar(paths[2], vars[2])

        axis.append(fig.add_subplot(1, 1, 1))

        #first y-axis
        color = 'tab:red'
        axis[0].set_xlabel(name(vars[0]) + unit(paths[0], vars[0]))
        axis[0].set_ylabel(name(vars[1]) + unit(paths[1], vars[1]))
        axis[0].plot(x, y1, color=color)
        axis[0].tick_params(axis=vars[1], labelcolor=color)

        #second y-axis
        axis[1] = axis[0].twinx(
        )  # instantiate a second axes that shares the same x-axis
        color = 'tab:blue'
        axis[1].plot(x, y2, color=color)
        axis[1].set_ylabel(name(vars[2]) + unit(paths[2], vars[2]))
        axis[1].tick_params(axis=vars[2], labelcolor=color)
        plt.title(
            header_info_to_plot(path1) + "\nPlot " + name(vars[1]) + "and " +
            name(vars[2]) + " against " + name(vars[0]))
        data.append(pd.Series(y1, index=x))
        data.append(pd.Series(y2, index=x))
        return axis, data
Ejemplo n.º 8
0
 def get_axis_lable(self):
     return name(self.var) + unit(self.path, self.var)
Ejemplo n.º 9
0
    def plotFunction(self, paths, vars, fig, state):

        #clears all info
        self.clear()
        nbr = len(paths)
        self.place = -1  # keeps track of if any path was used to the x-axis, and if so not to be added to a y-axis
        if default_time(state) is True and checkIfTimeAvailable(
                paths, vars) is True:  # check if time on x-axis
            plot_to_time = True
        else:
            plot_to_time = False
        """
        So far we are not working with neither data nor axis just creating x, y1, y2
        """
        # First find which data that should be x-axis
        # possible options is time, index or data form path.
        Temp = get_data_to_plot(paths[0], vars[0])
        if nbr == 1 and plot_to_time is False:
            self._add_index_to_xAxis(paths[0], Temp[0])
            for itm in Temp:
                self.add_to_y_axis(paths[0], vars[0], itm)
        else:
            if plot_to_time is True:
                self._add_time_to_xAxis(paths[0])
            else:
                for i in range(len(paths)):
                    Temp = get_data_to_plot(paths[i], vars[i])
                    if len(Temp) == 1 and self.x.isEmpty == True:
                        self.add_to_x_axis(paths[i], vars[i], Temp)
                        self.place = i
            if self.x.isEmpty == True:
                self._add_index_to_xAxis(paths[0], Temp)

            # now we have data stored in x

            # find the data to store in y1 and y2 or just y1

            for i in range(0, len(paths)):
                if i != self.place:
                    path = paths[i]
                    var = vars[i]
                    Temp = get_data_to_plot(path, var)
                    for temp_data in Temp:
                        self.add_to_y_axis(path, var, temp_data)
        """
        now we move on the defining axis and data using x, y1, y2
        """
        # use x, y1 and y2 to generate the axis and data to return

        # first handle y1 meaning working with axis[0]
        if self.y1.isEmpty == False:
            self._createAxis(fig)
            color = 'black'
            self.axis[0].set_xlabel(self.x.get_axis_lable())
            self.axis[0].set_ylabel(self.y1.get_axis_lable(), color=color)
            self.axis[0].plot(self.x.getData(),
                              self.y1.getData(),
                              color=color,
                              label=name(self.y1.getVar()))
            self.axis[0].tick_params(axis='y', labelcolor=color)

        # if two y-axis add the second one
        if self.y2.isEmpty == False:
            self._appendAxis(
            )  # instantiate a second axes that shares the same x-axis
            color = 'tab:blue'
            self.axis[1].plot(self.x.getData(),
                              self.y2.getData(),
                              color=color,
                              label=name(self.y2.getVar()))
            self.axis[1].set_ylabel(self.y2.get_axis_lable(), color=color)
            self.axis[1].tick_params(axis='y', labelcolor=color)

        # set titel to entire plot handeling all diferent cases
        if self.y2.isEmpty == True:
            self.axis[0].set_title(
                header_plot(paths[0]) + "\n Plot " + name(self.y1.getVar()) +
                " against " + name(self.x.getVar()))
        elif self.y2.isEmpty == False:
            self.axis[0].set_title(
                header_plot(paths[0]) + "\n Plot " + name(self.y1.getVar()) +
                ' and ' + name(self.y2.getVar()) + " against " +
                name(self.x.getVar()))

        self._append_data()

        return self.axis, self.data