Пример #1
0
def main():

    # Get the command line arguments
    args = docopt(__doc__)

    fileNames = args['<reduce-files>']
    estimatorToPlot = args['--estimator']
    NDIM = int(args['--ndim'])
    plotType = args['--plot_type']
    title = args['--title']
    hval = args['--hline'] and float(args['--hline'])

    if args['--hline']:
        if args['--hlabel']:
            hlabel = args['--hlabel']
        else:
            hlabel = '%s = %5.2f' % (estimatorToPlot[0], hval)

    if args['--legend']:
        varLabel = [l for l in args['--legend']]
    else:
        varLabel = [None]

    xLim = args['--xlim'] and [float(x) for x in args['--xlim']]
    yLim = args['--ylim'] and [float(y) for y in args['--ylim']]

    # Analyze the imput files
    reduce = pimchelp.ScalarReduce(fileNames, None)

    # Get a color scheme and marker list
    numColors = max(reduce.getNumVarParams(), 2)
    markers, colors = plotoptions.markersColors(numColors)

    # create a description object
    descrip = pimchelp.Description(NDIM)

    # get the plot options
    pOptions = plotoptions.plotOptions(plotType)

    # Plot each estimator
    for n, est in enumerate(estimatorToPlot):
        plt.figure(n + 1)
        ax = plt.subplot(111)
        if title:
            plt.title(title)

        # Add a possible horizontal line indicating some value
        if args['--hline']:
            plt.axhline(y=hval, color='#4d4d4d', linewidth=2.0, label=hlabel)

        for i in range(reduce.getNumVarParams()):
            lab = reduce.getVarLabel(i)
            if not lab or varLabel:
                lab = varLabel[i]
            pOptions['color'] = colors[i]

            # fill between to represent error bars
            if 'f' in plotType:
                emin = reduce.estimator(est, i) - reduce.estimatorError(est, i)
                emax = reduce.estimator(est, i) + reduce.estimatorError(est, i)
                plt.fill_between(reduce.param(),
                                 emax,
                                 emin,
                                 color=colors[i],
                                 alpha=0.2)
            # plot with points
            if 'p' in plotType:
                plt.plot(reduce.param(),
                         reduce.estimator(est, i),
                         markerfacecolor=colors[i],
                         label=lab,
                         **pOptions)

            # plot lines only
            if plotType == 'l':
                plt.plot(reduce.param(),
                         reduce.estimator(est, i),
                         label=lab,
                         **pOptions)
            # plot errorbars
            elif 'e' in plotType:
                print pOptions
                eb = plt.errorbar(reduce.param(),
                                  reduce.estimator(est, i),
                                  yerr=reduce.estimatorError(est, i),
                                  label=lab)

                # Set the width of the cap lines
                # for cap in eb[1]:
                #     cap.set_mew(2.0)

        plt.xlabel(descrip.paramLongName[reduce.reduceLabel], labelpad=16)
        plt.ylabel(descrip.estimatorLongName[est])
        leg = plt.legend(frameon=False, loc='best', prop={'size': 18})
        if xLim != []:
            plt.xlim(xLim[0], xLim[1])

        if yLim != []:
            plt.ylim(yLim[0], yLim[1])

    plt.show()
def main():

    # parse the command line options
    args = docopt(__doc__)

    fileNames = args["<file>"]
    estimatorToPlot = args["--estimator"]
    NDIM = int(args["--ndim"])
    plotType = args["--plot"]
    varLabel = args["--label"]
    xLim = args["--xLim"]
    yLim = args["--yLim"]

    # don't want any empty lists
    # if varLabel == []:
    #    varLabel = None
    if xLim == []:
        xLim = None
    if yLim == []:
        yLim = None

    if len(fileNames) < 1:
        sys.exit("\nNeed to specify at least one scalar estimator file\n")

    # Analyze the imput files
    # reduce = pimchelp.ScalarReduce(fileNames,varLabel)
    reduce = pimchelp.ScalarReduce(fileNames, None)

    # Get a color scheme and marker list
    numColors = max(reduce.getNumVarParams(), 2)
    markers, colors = plotoptions.markersColors(numColors)

    # create a description object
    descrip = pimchelp.Description(NDIM)

    # get the plot options
    pOptions = plotoptions.plotOptions(plotType)

    # Plot each estimator
    for n, est in enumerate(estimatorToPlot):
        if args["--same"]:
            pl.figure(1)
        else:
            pl.figure(n + 1)
        ax = pl.subplot(111)
        for i in range(reduce.getNumVarParams()):
            if args["--same"]:
                lab = varLabel[n]
            else:
                lab = reduce.getVarLabel(i)
            pOptions["color"] = colors[i]
            if "p" in plotType:
                pl.plot(reduce.param(), reduce.estimator(est, i), markerfacecolor=colors[i], label=lab, **pOptions)
            if plotType == "l":
                pl.plot(reduce.param(), reduce.estimator(est, i), label=lab, **pOptions)
            elif "e" in plotType:
                if args["--same"]:
                    eb = pl.errorbar(
                        reduce.param(),
                        reduce.estimator(est, i),
                        yerr=reduce.estimatorError(est, i),
                        markerfacecolor=colors[i + n],
                        ecolor=colors[i + n],
                        label=lab,
                        **pOptions
                    )
                else:
                    eb = pl.errorbar(
                        reduce.param(),
                        reduce.estimator(est, i),
                        yerr=reduce.estimatorError(est, i),
                        markerfacecolor=colors[i],
                        ecolor=colors[i],
                        label=lab,
                        **pOptions
                    )

                # Set the width of the cap lines
                for cap in eb[1]:
                    cap.set_mew(2.0)

        # pl.tight_layout()
        pl.xlabel(descrip.paramLongName[reduce.reduceLabel], fontsize=18)
        pl.ylabel(descrip.estimatorLongName[est], fontsize=18)
        leg = pl.legend(frameon=False, loc="best", prop={"size": 18})
        if xLim != None:
            pl.xlim(xLim[0], xLim[1])

        if yLim != None:
            pl.ylim(yLim[0], yLim[1])
        pl.grid(True)

    pl.show()
def main(): 

    # Get the command line arguments
    args = docopt(__doc__)

    fileNames = args['<reduce-files>']
    estimatorToPlot = args['--estimator']
    NDIM = int(args['--ndim'])
    plotType = args['--plot_type']
    title = args['--title']
    hval = args['--hline'] and float(args['--hline'])

    if args['--hline']:
        if args['--hlabel']:
            hlabel = args['--hlabel']
        else:
            hlabel = '%s = %5.2f' % (estimatorToPlot[0],hval)

    if args['--legend']:
        varLabel = [l for l in args['--legend']]
    else: 
        varLabel = [None]

    xLim = args['--xlim'] and [float(x) for x in args['--xlim']]
    yLim = args['--ylim'] and [float(y) for y in args['--ylim']]

    # Analyze the imput files
    reduce = pimchelp.ScalarReduce(fileNames,None)

    # Get a color scheme and marker list
    numColors = max(reduce.getNumVarParams(),2)
    markers,colors  = plotoptions.markersColors(numColors)

    # create a description object
    descrip = pimchelp.Description(NDIM)

    # get the plot options
    pOptions = plotoptions.plotOptions(plotType)

    # Plot each estimator
    for n,est in enumerate(estimatorToPlot):
        plt.figure(n+1)
        ax = plt.subplot(111)
        if title:
            plt.title(title)

        # Add a possible horizontal line indicating some value
        if args['--hline']:
            plt.axhline(y=hval,color='#4d4d4d',linewidth=2.0,label=hlabel)

        for i in range(reduce.getNumVarParams()):
            lab = reduce.getVarLabel(i)
            if not lab or varLabel:
                lab = varLabel[i]
            pOptions['color'] = colors[i]

            # fill between to represent error bars
            if 'f' in plotType:
                emin = reduce.estimator(est,i)-reduce.estimatorError(est,i)
                emax = reduce.estimator(est,i)+reduce.estimatorError(est,i)
                plt.fill_between(reduce.param(), emax,emin, color=colors[i],
                                alpha=0.2)
            # plot with points
            if 'p' in plotType:
                plt.plot(reduce.param(), reduce.estimator(est,i),
                        markerfacecolor=colors[i],label=lab, **pOptions)

            # plot lines only
            if plotType == 'l':
                plt.plot(reduce.param(), reduce.estimator(est,i),
                        label=lab,**pOptions)
            # plot errorbars
            elif 'e' in plotType:
                eb = plt.errorbar(reduce.param(), reduce.estimator(est,i),
                        yerr=reduce.estimatorError(est,i), 
                        markerfacecolor=colors[i], ecolor=colors[i],
                        label=lab, **pOptions)

                # Set the width of the cap lines
                # for cap in eb[1]:
                #     cap.set_mew(2.0)

            
        plt.xlabel(descrip.paramLongName[reduce.reduceLabel],labelpad=16)
        plt.ylabel(descrip.estimatorLongName[est])
        leg = plt.legend(frameon=False, loc='best', prop={'size':18})
        if xLim != []:
            plt.xlim(xLim[0],xLim[1])

        if yLim != []:
            plt.ylim(yLim[0],yLim[1])

    plt.show()
Пример #4
0
def main():

    # setup the argument parser
    parser = argparse.ArgumentParser(description='Plot a vector estimator.')
    parser.add_argument('fileNames',
                        help='Reduced scalar estimator files',
                        nargs='+')
    parser.add_argument('--ndim',
                        '-d',
                        help='Number of spatial dimensions.',
                        type=int,
                        default=3)
    parser.add_argument('--plot',
                        '-p',
                        help='The plot type. l = lines, p = points, \
                        e = errorbars',
                        type=str,
                        choices=['l', 'e', 'p', 'lp', 'le'],
                        default='e')
    parser.add_argument('--label',
                        '-l',
                        help='Parameter name for labels.',
                        type=str)
    parser.add_argument('--subplot',
                        '-s',
                        help='Dimensions of a subplot matrix.',
                        type=int,
                        nargs='+')
    parser.add_argument('--xlim',
                        '-x',
                        help='x-axis limits',
                        type=float,
                        nargs='+')
    parser.add_argument('--ylim',
                        '-y',
                        help='y-axis limits',
                        type=float,
                        nargs='+')
    parser.add_argument('--log',
                        help='Set y-axis log scale',
                        action='store_true')
    args = parser.parse_args()

    fileNames = args.fileNames
    NDIM = args.ndim
    varLabel = args.label
    plotType = args.plot
    subplot = args.subplot
    xLim = args.xlim
    yLim = args.ylim
    log = args.log

    if len(fileNames) < 1:
        parser.error("Need to specify at least one vector estimator file")

    # Analyze the imput files
    estimatorName = pimchelp.getVectorEstimatorName(fileNames[0])
    print estimatorName
    reduce = pimchelp.VectorReduce(fileNames, estimatorName, varLabel)

    # Get a color scheme and marker list
    numColors = reduce.getNumReduceParams()
    markers, colors = plotoptions.markersColors(numColors)

    # get the plot options
    pOptions = plotoptions.plotOptions(plotType)

    # create a description object
    descrip = pimchelp.Description(NDIM)

    # Plot each estimator
    for varIndex in range(reduce.getNumVarParams()):
        pl.figure(varIndex + 1)
        #ax = pl.subplot(111)

        for reduceIndex in range(reduce.getNumReduceParams()):
            lab = reduce.getReduceLabel(reduceIndex)
            pOptions['color'] = colors[reduceIndex]
            if 'e' in plotType:
                eb = pl.errorbar(reduce.x(varIndex, reduceIndex),
                                 reduce.estimator(varIndex, reduceIndex),
                                 yerr=reduce.estimatorError(
                                     varIndex, reduceIndex),
                                 markerfacecolor=colors[reduceIndex],
                                 ecolor=colors[reduceIndex],
                                 label=lab,
                                 **pOptions)

                # Set the width of the cap lines
                for cap in eb[1]:
                    cap.set_mew(1.0)
            else:
                pl.plot(reduce.x(varIndex, reduceIndex),
                        reduce.estimator(varIndex, reduceIndex),
                        label=lab,
                        **pOptions)

        pl.xlabel(descrip.estimatorXLongName[estimatorName])
        pl.ylabel(descrip.estimatorLongName[estimatorName])
        leg = pl.legend(frameon=False, loc='best', prop={'size': 18})

        #        # Add a colorbar
        #        cmap = loadgmt.getcmap('cb/div','Spectral_08')
        #        T = reduce.param()[::2]
        #        cb = pl.colorbar(loadgmt.getMap(cmap,T),ax=ax,ticks=T)
        #        cb.ax.set_ylabel('Temperature',rotation=-90)

        if xLim != None:
            pl.xlim(xLim[0], xLim[1])

        if yLim != None:
            pl.ylim(yLim[0], yLim[1])

        # Set a log scale
        if log:
            ax = pl.subplot(111)
            ax.set_yscale('log')

    # Plot a possible subplot matrix
    if subplot != None:
        f, ax = pl.subplots(subplot[0],
                            subplot[1],
                            sharex=True,
                            squeeze=False,
                            sharey=True)
        numReduce = reduce.getNumReduceParams()

        for reduceIndex in range(reduce.getNumReduceParams()):
            id = getIndex(reduceIndex, subplot, 2)
            pOptions['color'] = colors[reduceIndex]
            lab = reduce.getReduceLabel(reduceIndex)

            for varIndex in range(reduce.getNumVarParams()):
                pOptions['marker'] = markers[varIndex]

                if 'e' in plotType:
                    eb = ax[id[0], id[1]].errorbar(
                        reduce.x(varIndex, reduceIndex),
                        reduce.estimator(varIndex, reduceIndex),
                        yerr=reduce.estimatorError(0, reduceIndex),
                        markerfacecolor=colors[reduceIndex],
                        ecolor=colors[reduceIndex],
                        label=lab,
                        **pOptions)

                    # Set the width of the cap lines
                    for cap in eb[1]:
                        cap.set_mew(1.0)
                else:
                    ax[id[0],
                       id[1]].plot(reduce.x(varIndex, reduceIndex),
                                   reduce.estimator(varIndex, reduceIndex),
                                   label=lab,
                                   **pOptions)

            ax[id[0], id[1]].legend(frameon=False,
                                    loc='upper left',
                                    prop={'size': 18})
            if xLim != None:
                ax[id[0], id[1]].set_xlim(xLim[0], xLim[1])

            if yLim != None:
                ax[id[0], id[1]].set_ylim(yLim[0], yLim[1])

        [
            ax[-1, n].set_xlabel(descrip.estimatorXLongName[estimatorName])
            for n in range(subplot[1])
        ]
        [
            ax[n, 0].set_ylabel(descrip.estimatorLongName[estimatorName])
            for n in range(subplot[0])
        ]
        f.subplots_adjust(hspace=0.10)
        f.subplots_adjust(wspace=0.10)

    pl.show()
def main(): 

    # setup the argument parser
    parser = argparse.ArgumentParser(description='Plot a vector estimator.')
    parser.add_argument('fileNames', help='Reduced scalar estimator files', nargs='+')
    parser.add_argument('--ndim', '-d', help='Number of spatial dimensions.',
                        type=int, default=3) 
    parser.add_argument('--plot','-p', help='The plot type. l = lines, p = points, \
                        e = errorbars', type=str, choices=['l','e','p','lp','le'], 
                        default='e')
    parser.add_argument('--label', '-l', help='Parameter name for labels.', type=str)
    parser.add_argument('--subplot', '-s', help='Dimensions of a subplot matrix.', 
                        type=int, nargs='+')
    parser.add_argument('--xlim', '-x', help='x-axis limits', type=float,
                        nargs='+')
    parser.add_argument('--ylim', '-y', help='y-axis limits', type=float,
                        nargs='+')
    parser.add_argument('--log', help='Set y-axis log scale',
                        action='store_true')
    args = parser.parse_args()

    fileNames = args.fileNames
    NDIM = args.ndim
    varLabel = args.label
    plotType = args.plot
    subplot = args.subplot
    xLim = args.xlim
    yLim = args.ylim
    log = args.log

    if len(fileNames) < 1:
        parser.error("Need to specify at least one vector estimator file")

    # Analyze the imput files
    estimatorName = pimchelp.getVectorEstimatorName(fileNames[0])
    print estimatorName
    reduce = pimchelp.VectorReduce(fileNames,estimatorName,varLabel)

    # Get a color scheme and marker list
    numColors = reduce.getNumReduceParams()
    markers,colors  = plotoptions.markersColors(numColors)

    # get the plot options
    pOptions = plotoptions.plotOptions(plotType)

    # create a description object
    descrip = pimchelp.Description(NDIM)

    # Plot each estimator
    for varIndex in range(reduce.getNumVarParams()):
        pl.figure(varIndex+1)
        #ax = pl.subplot(111)

        for reduceIndex in range(reduce.getNumReduceParams()):
            lab = reduce.getReduceLabel(reduceIndex)
            pOptions['color'] = colors[reduceIndex]
            if 'e' in plotType:
                eb = pl.errorbar(reduce.x(varIndex,reduceIndex),
                                 reduce.estimator(varIndex,reduceIndex),
                                 yerr=reduce.estimatorError(varIndex,reduceIndex), 
                                 markerfacecolor=colors[reduceIndex],
                                 ecolor=colors[reduceIndex], label=lab, 
                                 **pOptions)
                
                # Set the width of the cap lines
                for cap in eb[1]:
                    cap.set_mew(1.0)
            else:
                pl.plot(reduce.x(varIndex,reduceIndex),
                        reduce.estimator(varIndex,reduceIndex),
                        label=lab, **pOptions)


        pl.xlabel(descrip.estimatorXLongName[estimatorName])
        pl.ylabel(descrip.estimatorLongName[estimatorName])
        leg = pl.legend(frameon=False, loc='best', prop={'size':18})

#        # Add a colorbar
#        cmap = loadgmt.getcmap('cb/div','Spectral_08')
#        T = reduce.param()[::2]
#        cb = pl.colorbar(loadgmt.getMap(cmap,T),ax=ax,ticks=T)
#        cb.ax.set_ylabel('Temperature',rotation=-90)

        if xLim != None:
            pl.xlim(xLim[0],xLim[1])

        if yLim != None:
            pl.ylim(yLim[0],yLim[1])

        # Set a log scale
        if log:
            ax = pl.subplot(111)
            ax.set_yscale('log')


    # Plot a possible subplot matrix
    if subplot != None:
        f, ax = pl.subplots(subplot[0], subplot[1], sharex=True, squeeze=False, sharey=True)
        numReduce = reduce.getNumReduceParams()

        for reduceIndex in range(reduce.getNumReduceParams()):
            id = getIndex(reduceIndex,subplot,2)
            pOptions['color'] = colors[reduceIndex]
            lab = reduce.getReduceLabel(reduceIndex)

            for varIndex in range(reduce.getNumVarParams()):
                pOptions['marker'] = markers[varIndex]

                if 'e' in plotType:
                    eb = ax[id[0],id[1]].errorbar(reduce.x(varIndex,reduceIndex),
                                                  reduce.estimator(varIndex,reduceIndex),
                                                  yerr=reduce.estimatorError(0,reduceIndex), 
                                                  markerfacecolor=colors[reduceIndex],
                                                  ecolor=colors[reduceIndex], label=lab, 
                                                  **pOptions)
                    
                    # Set the width of the cap lines
                    for cap in eb[1]:
                        cap.set_mew(1.0)
                else:
                    ax[id[0],id[1]].plot(reduce.x(varIndex,reduceIndex),
                                         reduce.estimator(varIndex,reduceIndex),
                                         label=lab, **pOptions)

            ax[id[0],id[1]].legend(frameon=False, loc='upper left', prop={'size':18})
            if xLim != None:
                ax[id[0],id[1]].set_xlim(xLim[0],xLim[1])

            if yLim != None:
                ax[id[0],id[1]].set_ylim(yLim[0],yLim[1])

        [ax[-1,n].set_xlabel(descrip.estimatorXLongName[estimatorName]) for n in range(subplot[1])]
        [ax[n,0].set_ylabel(descrip.estimatorLongName[estimatorName]) for n in range(subplot[0])]
        f.subplots_adjust(hspace=0.10)
        f.subplots_adjust(wspace=0.10)

    pl.show()
Пример #6
0
def main():

    # parse the command line options
    args = docopt(__doc__)

    fileNames = args['<file>']
    estimatorToPlot = args['--estimator']
    NDIM = int(args['--ndim'])
    plotType = args['--plot']
    varLabel = args['--label']
    xLim = args['--xLim']
    yLim = args['--yLim']

    # don't want any empty lists
    #if varLabel == []:
    #    varLabel = None
    if xLim == []:
        xLim = None
    if yLim == []:
        yLim = None

    if len(fileNames) < 1:
        sys.exit("\nNeed to specify at least one scalar estimator file\n")

    # Analyze the imput files
    #reduce = pimchelp.ScalarReduce(fileNames,varLabel)
    reduce = pimchelp.ScalarReduce(fileNames, None)

    # Get a color scheme and marker list
    numColors = max(reduce.getNumVarParams(), 2)
    markers, colors = plotoptions.markersColors(numColors)

    # create a description object
    descrip = pimchelp.Description(NDIM)

    # get the plot options
    pOptions = plotoptions.plotOptions(plotType)

    # Plot each estimator
    for n, est in enumerate(estimatorToPlot):
        if args['--same']:
            pl.figure(1)
        else:
            pl.figure(n + 1)
        ax = pl.subplot(111)
        for i in range(reduce.getNumVarParams()):
            if args['--same']:
                lab = varLabel[n]
            else:
                lab = reduce.getVarLabel(i)
            pOptions['color'] = colors[i]
            if 'p' in plotType:
                pl.plot(reduce.param(),
                        reduce.estimator(est, i),
                        markerfacecolor=colors[i],
                        label=lab,
                        **pOptions)
            if plotType == 'l':
                pl.plot(reduce.param(),
                        reduce.estimator(est, i),
                        label=lab,
                        **pOptions)
            elif 'e' in plotType:
                if args['--same']:
                    eb = pl.errorbar(reduce.param(),
                                     reduce.estimator(est, i),
                                     yerr=reduce.estimatorError(est, i),
                                     markerfacecolor=colors[i + n],
                                     ecolor=colors[i + n],
                                     label=lab,
                                     **pOptions)
                else:
                    eb = pl.errorbar(reduce.param(),
                                     reduce.estimator(est, i),
                                     yerr=reduce.estimatorError(est, i),
                                     markerfacecolor=colors[i],
                                     ecolor=colors[i],
                                     label=lab,
                                     **pOptions)

                # Set the width of the cap lines
                for cap in eb[1]:
                    cap.set_mew(2.0)

        #pl.tight_layout()
        pl.xlabel(descrip.paramLongName[reduce.reduceLabel], fontsize=18)
        pl.ylabel(descrip.estimatorLongName[est], fontsize=18)
        leg = pl.legend(frameon=False, loc='best', prop={'size': 18})
        if xLim != None:
            pl.xlim(xLim[0], xLim[1])

        if yLim != None:
            pl.ylim(yLim[0], yLim[1])
        pl.grid(True)

    pl.show()