Exemplo n.º 1
0
def plot_points_3D( filenames, show = True, fignum = 1, 
                    axislabels = None ):
    """
    Plot a set of points specified by coordinates contained within filename
    The input file should contain the x1, x2 and x3 coordinates of each point 
    in csv format. E.g. A file with 4 points may look like
    0.5,0.5,0.5, 0.5
    0.5,1.0,0.5, 0.0
    0.5,0.0,0.5, 0.0
    """
    if ( not type(filenames ) == type([]) ):
        filenames = [filenames]

    colors = ['k','r','b','g']
    markers = ['o','^','8','s']

    fig = pylab.figure( fignum )
    ax = p3.Axes3D( fig )
    i = 0
    for filename in filenames:
        data = file_utils.read_csv_floats( filename )
        assert data.shape[0] == 3
        ax.scatter3D( data[0,:], data[1,:], data[2,:], c = colors[i], 
                      marker = markers[0] )
        i += 1
    
    if ( axislabels is not None ):
        ax.set_xlabel( axislabels[0] )
        ax.set_ylabel( axislabels[1] )
        ax.set_zlabel( axislabels[2] )

    if ( show ):
        pylab.show()
Exemplo n.º 2
0
def plot_sub_space_indices( filename,show = True,fignum = 1,
                            otherfilename = None,
                            title = None ):
    pylab.figure( fignum )
    data = file_utils.read_csv_floats( filename )
    assert data.shape[1] == 2
    #pylab.plot(data[:,0],data[:,1],'ok')
    xMax = numpy.max( data[:,0] )
    yMax = numpy.max( data[:,1] )
    for i in range(data.shape[0]):
        box = numpy.array( [[data[i,0]-1,data[i,1]-1],
                          [data[i,0],data[i,1]-1],
                          [data[i,0],data[i,1]],
                          [data[i,0]-1,data[i,1]],
                          [data[i,0]-1,data[i,1]-1]] ) + 0.5
        p1 = pylab.plot( box[:,0], box[:,1], '-k' )
    #pylab.legend((p1),("sparse grid indices"),loc=0)

    if ( otherfilename is not None ):
        data = file_utils.read_csv_floats( otherfilename )
        if (data.shape[0] > 0 ):
            for i in range( data.shape[0] ):
                box = numpy.array( [[data[i,0]-1,data[i,1]-1],
                                  [data[i,0],data[i,1]-1],
                                  [data[i,0],data[i,1]],
                                  [data[i,0]-1,data[i,1]],
                                  [data[i,0]-1,data[i,1]-1]] ) + 0.5
                p2 = pylab.plot( box[:,0], box[:,1], '-r' )
            xMaxNew = numpy.max( data[:,0] )
            xMax = max( xMax, xMaxNew )
            yMaxNew = numpy.max( data[:,1] )
            yMax = max( yMax, yMaxNew )
            pylab.legend( (p1,p2), ('sparse grid indices',
                                    'active sparse grid indices'), loc = 0 )

    lim = max( xMax, yMax )
    pylab.xticks( numpy.arange( 0, lim + 1 ) )
    pylab.yticks( numpy.arange( 0, lim + 1) )
    pylab.xlim( -0.5, lim + 1 )
    pylab.ylim( -0.5, lim + 1 )

    if ( title is not None ):
        pylab.title( title )

    if ( show ):
        pylab.show()
Exemplo n.º 3
0
def plot_points( filenames, show = True, fignum = 1, 
                 axislabels = None, title = None, fontsize = 12,
                 markersize = 2 ):
    """
    Plot a set of points specified by coordinates contained within filename
    The input file should contain the x1 and x2 coordinates of each point in
    csv format. E.g.
    0.5,0.5,0.5
    0.5,1.0,0.0
    """

    params = { 'lines.markersize': markersize,
               'font.size': fontsize }
    pylab.rcParams.update( params )

    if ( not type(filenames) == type([]) ):
        filenames = [filenames]

    pylab.figure( fignum )
    colors = ['k','r','b','g','m','y','c']

    i = 0
    for filename in filenames:
        data = file_utils.read_csv_floats( filename )
        if ( len( data ) > 0 ):
            assert data.shape[0] == 2
            pylab.plot( data[0,:], data[1,:], marker='o',
                        color = colors[i],
                        linestyle = "" )
            i += 1
            if ( i > 6 ):
                break

    if ( axislabels is not None ):
        pylab.xlabel( axislabels[0] )
        pylab.ylabel( axislabels[1], rotation='horizontal' )

    if ( title is not None ):
        pylab.title( title )
        
    if ( show ):
        pylab.show()
Exemplo n.º 4
0
def plot_surface_from_file_function_values( filename, numPts1D,
                                            degreeOfFreedom = 0,
                                            transposeData = False,
                                            domain = None,
                                            show = True,
                                            fignum = 1,
                                            axislabels = None,
                                            title = None ):
    """
    File must be a ( nDOF x nPts ) matrix
    """

    data = file_utils.read_csv_floats( filename )
    if ( transposeData ):
        data = numpy.transpose( data );
    data = data[degreeOfFreedom,:]
    plot_surface_from_function_values( data,
                                       domain = domain,
                                       numPts1D = numPts1D,
                                       show = show,
                                       fignum = fignum,
                                       axislabels = axislabels,
                                       title = title )
Exemplo n.º 5
0
def plotPointClasses( basename, show = True, colors = None ):
    assert type( basename ) == type("")
    
    filename = addExtension( basename,".csv" )
    data = file_utils.read_csv_floats( filename )
    assert data.shape[1] == 4
    
    k = 0
    classSets = []
    classNumbers = {}
    classNumbers[int(data[0,3])] = k
    classSets.append( [data[0,:2]] )
    for i in range ( 1, data.shape[0] ):
        if ( classNumbers.has_key( int(data[i,3]) ) ):
            classSets[classNumbers[int(data[i,3])]].append( data[i,:2] )
        else:
            k += 1
            classNumbers[int(data[i,3])] = k
            classSets.append( [data[i,:2]] )

    if colors is not None:
        if len( colors ) != len( classSets ):
            colors = None
            msg = "Warning: (PlotPointClasses) The number of colors specified does not match the number of classes. Reverting to default colors."
            print msg

    pylab.figure()
    for i in range( len( classSets ) ):
        points = numpy.array( classSets[i] )
        if colors is None:
            pylab.plot( points[:,0], points[:,1], 'o' )
        else:
            pylab.plot( points[:,0], points[:,1], marker = 'o',
                        color = colors[i], linestyle = 'None')

    if ( show ):
        pylab.show()