def AverageTimeSeries(self,means,stds,time,nstd,datatype,labels,linestyle,linewidth,marker,ms,colors,title,xlabel,ylabel,is_legend,legend_location):
        """       
        Plots the average and standard deviation of datatype on a regular grid.

        Input:
         - *means* (array)
         - *stds* (array)
         - *time* (array)
         - *nstd* (float)
         - *datatype* (list)
         - *labels* (list)     
         - *linestyle* (string)
         - *linewidth* (float)
         - *marker* (string)
         - *ms* (float)
         - *colors* (list)       
         - *title* (string)
         - *xlabel* (string)
         - *ylabel* (string)
         - *is_legend* (boolean)
         - *legend_location* [default = 'upper right'] (string/integer)
        """ 
        assert nstd > 0, "Error: The number of STDs must be a value larger than zero"
        plt.figure(self.plotnum)
        datatype_indices = [labels.index(Id) for Id in datatype] 
        j=0
        for i in datatype_indices:
            if colors == None:              
                if j >= len(self.colors):                  
                    j=0
            elif isinstance(colors,list):
                if j >= len(colors):
                    j=0
            elif isinstance(colors,str):
                colors = [colors]
                j=0          
            
            # plot with y-axis error bars
            if colors == None:
                plt.errorbar(time,means[:,i],yerr = nstd*np.array(stds[:,i]),color = self.colors[j],ls = linestyle,lw=linewidth,marker = marker,ms=ms,label = labels[i]) 
            else:
                if clr.is_color_like(colors[j]):     
                    plt.errorbar(time,means[:,i],yerr = nstd*np.array(stds[:,i]),color = colors[j],ls = linestyle,lw=linewidth,marker = marker,ms=ms,label = labels[i])
                else:
                    print("*** WARNING ***: '{0}' is not recognized as a valid color code".format(colors[j]) )
                    plt.errorbar(time,means[:,i],yerr = nstd*np.array(stds[:,i]),color = self.colors[j],ls = linestyle,lw=linewidth,marker = marker,ms=ms,label = labels[i])
                    colors = None
            j+=1
        if is_legend:
            plt.legend(numpoints=1,frameon=True,loc=legend_location)
        plt.title(title)
        plt.xlabel(xlabel)
        plt.ylabel(ylabel)
Example #2
0
    def AverageDistributions(self, means, stds, nstd, datatype, labels,
                             linestyle, linewidth, marker, colors, title,
                             xlabel, ylabel, is_legend, legend_location):
        """      
        Plots the average and standard deviation.

        Input:
         - *means* (nested list)
         - *stds* (nested list)
         - *nstd* (float)
         - *labels* (list)
         - *linestyle* (string)
         - *linewidth* (float)
         - *marker* (string)
         - *colors* (list)
         - *title* (string)
         - *xlabel* (string)
         - *ylabel* (string)
         - *is_legend* (boolean)
         - *legend_location* [default = 'upper right'] (string/integer)
        """
        assert nstd > 0, "Error: The number of STDs must be a value larger than zero"
        plt.figure(self.plotnum)
        datatype_indices = [labels.index(Id) for Id in datatype]
        j = 0
        for i in datatype_indices:
            if colors == None:
                if j >= len(self.colors):
                    j = 0
            elif isinstance(colors, list):
                if j >= len(colors):
                    j = 0
            elif isinstance(colors, str):
                colors = [colors]
                j = 0
            if colors == None:
                plt.errorbar(means[i][0],
                             means[i][1],
                             yerr=nstd * np.array(stds[i][1]),
                             color=self.colors[j],
                             ls=linestyle,
                             lw=linewidth,
                             marker=marker,
                             label=labels[i])  # plot with y-axis error bars
            else:
                if clr.is_color_like(colors[j]):
                    plt.errorbar(means[i][0],
                                 means[i][1],
                                 yerr=nstd * np.array(stds[i][1]),
                                 color=colors[j],
                                 ls=linestyle,
                                 lw=linewidth,
                                 marker=marker,
                                 label=labels[i])
                else:
                    print(
                        "*** WARNING ***: '{0}' is not recognized as a valid color code"
                        .format(colors[j]))
                    plt.errorbar(means[i][0],
                                 means[i][1],
                                 yerr=nstd * np.array(stds[i][1]),
                                 color=self.colors[j],
                                 ls=linestyle,
                                 lw=linewidth,
                                 marker=marker,
                                 label=labels[i])
                    colors = None
            j += 1
        if is_legend:
            plt.legend(numpoints=1, frameon=True, loc=legend_location)
        plt.title(title)
        plt.xlabel(xlabel)
        plt.ylabel(ylabel)