Example #1
0
    def _plot(self):

        var = self.vars[0]
        mesh = var.mesh

        U, V = var.numericValue

        U = numerix.take(U, self.indices)
        V = numerix.take(V, self.indices)

        ang = numerix.arctan2(V, U)
        mag = numerix.sqrt(U**2 + V**2)

        datamin, datamax = self._autoscale(vars=(mag, ),
                                           datamin=self._getLimit('datamin'),
                                           datamax=self._getLimit('datamax'))

        mag = numerix.where(mag > datamax, datamax, mag)
        mag = numerix.ma.masked_array(mag, mag < datamin)

        if self.log:
            mag = numerix.log10(mag)
            mag = numerix.ma.masked_array(mag, numerix.isnan(mag))

        U = mag * numerix.cos(ang)
        V = mag * numerix.sin(ang)

        self._quiver.set_UVC(U, V)

        self.axes.set_xlim(xmin=self._getLimit('xmin'),
                           xmax=self._getLimit('xmax'))
        self.axes.set_ylim(ymin=self._getLimit('ymin'),
                           ymax=self._getLimit('ymax'))
Example #2
0
    def _plot(self):

        var = self.vars[0]
        mesh = var.mesh

        U, V = var.numericValue

        U = numerix.take(U, self.indices)
        V = numerix.take(V, self.indices)
        
        ang = numerix.arctan2(V, U)
        mag = numerix.sqrt(U**2 + V**2)
        
        datamin, datamax = self._autoscale(vars=(mag,),
                                           datamin=self._getLimit('datamin'),
                                           datamax=self._getLimit('datamax'))
        
        mag = numerix.where(mag > datamax, datamax, mag)
        mag = numerix.ma.masked_array(mag, mag < datamin)
        
        if self.log:
            mag = numerix.log10(mag)
            mag = numerix.ma.masked_array(mag, numerix.isnan(mag))
            
        U = mag * numerix.cos(ang)
        V = mag * numerix.sin(ang)

        self._quiver.set_UVC(U, V)
        
        self.axes.set_xlim(xmin=self._getLimit('xmin'),
                           xmax=self._getLimit('xmax'))
        self.axes.set_ylim(ymin=self._getLimit('ymin'),
                           ymax=self._getLimit('ymax'))
        def logs_to_signed(v, plus, minus):
            v = numerix.where(v > 0, plus, -minus)
            v = numerix.where(numerix.isnan(v), 0., v)

            return v
        def logs_to_signed(v, plus, minus):
            v = numerix.where(v > 0, plus, -minus)
            v = numerix.where(numerix.isnan(v), 0., v)

            return v
    def plot(self, matrix, RHSvector, log='auto'):
        import tempfile
        import os
        
        (f, mtxName) = tempfile.mkstemp(suffix='.mtx')
        matrix.exportMmf(mtxName)
        mtx = mmio.mmread(mtxName)
##         f.close()
        os.remove(mtxName)
        
        pylab.ion()
        
        c = mtx.tocoo()
        y = c.row
        x = c.col
        z = c.data
        
        b = RHSvector
        
        if len(z) == 0:
            y = zeros((1,))
            x = zeros((1,))
            z = zeros((1,))

        zPlus = where(z > 0, log10(z), nan)
        zMinus = where(z < 0, log10(-z), nan)
        bPlus = where(b > 0, log10(b), nan)
        bMinus = where(b < 0, log10(-b), nan)

        if (log == True
            or (log == 'auto' 
                and (max(zPlus) - min(zPlus) > 2
                     or max(zMinus) - min(zMinus) > 2
                     or max(bPlus) - min(bPlus) > 2
                     or max(bMinus) - min(bMinus) > 2))):
            log = True
        else:
            log = False
            
        if log:
            zMin = nanmin((nanmin(zPlus), nanmin(zMinus), nanmin(bPlus), nanmin(bMinus)))
            zMax = nanmax((nanmax(zPlus), nanmax(zMinus), nanmax(bPlus), nanmax(bMinus)))
##             zThreshold = 0.5 # (zMax - zMin) / 5.
            
            zMin -= 0.5
            
            numdec = math.floor(zMax)-math.ceil(zMin)
            if numdec < 0:
                zMax += 0.5
            
            zPlus -= zMin
            zMinus -= zMin
            bPlus -= zMin
            bMinus -= zMin
            zRange = zMax - zMin
            
            if zRange == 0:
                zRange = nanmax(zPlus) + 1

            z = where(z > 0, zPlus, -zMinus)
            z = where(isnan(z), 0., z)
            b = where(b > 0, bPlus, -bMinus)
            b = where(isnan(b), 0., b)

            fmt = SignedLogFormatter(threshold=zMin)
            loc = SignedLogLocator(threshold=zMin)
            
        else:
            zRange = max(max(abs(z)), max(abs(b)))
        
            if zRange == 0:
                zRange = 1

            fmt = None
            loc = None
            

        N = matrix._getShape()[0]
        saveSize = pylab.rcParams['figure.figsize']
        size = pylab.rcParams['figure.dpi'] **2 * saveSize[0] * saveSize[1] / N**2

        pylab.ioff()
        
        pylab.figure(self.id)
        pylab.clf()

        pylab.delaxes()
        ax1 = pylab.axes([self.margin, self.margin, self.width, self.width])
        
        Mscat = pylab.scatter(x, y, c=z, 
                              vmin=-zRange, vmax=zRange, edgecolors='none', 
                              cmap=pylab.get_cmap('RdBu'), marker='s', s=size)
                             
        ax2 = pylab.axes([self.width + self.margin, self.margin, (self.width / self.aspect) / N, self.width], 
                         sharey=ax1)

        bscat = pylab.scatter(zeros((N,)), arange(N), c=b, 
                              vmin=-zRange, vmax=zRange, edgecolors='none', 
                              cmap=pylab.get_cmap('RdBu'), marker='s', s=size)

        pylab.setp((ax2.get_xticklabels(),
                    ax2.get_yticklabels(),
                    ax2.get_xticklines(),
                    ax2.get_yticklines()), visible=False)
        
        pylab.axes(ax1)
        pylab.axis([-0.5, N - 0.5, N - 0.5, -0.5])

        pylab.colorbar(format=fmt, ticks=loc)

        pylab.title(self.title)

        pylab.draw()