示例#1
0
 def _h_arrows(self, length):
     """ length is in arrow width units """
     # It might be possible to streamline the code
     # and speed it up a bit by using complex (x,y)
     # instead of separate arrays; but any gain would be slight.
     minsh = self.minshaft * self.headlength
     N = len(length)
     length = length.reshape(N, 1)
     # x, y: normal horizontal arrow
     x = npy.array([0, -self.headaxislength, -self.headlength, 0],
                   npy.float64)
     x = x + npy.array([0, 1, 1, 1]) * length
     y = 0.5 * npy.array([1, 1, self.headwidth, 0], npy.float64)
     y = npy.repeat(y[npy.newaxis, :], N, axis=0)
     # x0, y0: arrow without shaft, for short vectors
     x0 = npy.array(
         [0, minsh - self.headaxislength, minsh - self.headlength, minsh],
         npy.float64)
     y0 = 0.5 * npy.array([1, 1, self.headwidth, 0], npy.float64)
     ii = [0, 1, 2, 3, 2, 1, 0]
     X = x.take(ii, 1)
     Y = y.take(ii, 1)
     Y[:, 3:] *= -1
     X0 = x0.take(ii)
     Y0 = y0.take(ii)
     Y0[3:] *= -1
     shrink = length / minsh
     X0 = shrink * X0[npy.newaxis, :]
     Y0 = shrink * Y0[npy.newaxis, :]
     short = npy.repeat(length < minsh, 7, axis=1)
     #print 'short', length < minsh
     # Now select X0, Y0 if short, otherwise X, Y
     X = ma.where(short, X0, X)
     Y = ma.where(short, Y0, Y)
     if self.pivot[:3] == 'mid':
         X -= 0.5 * X[:, 3, npy.newaxis]
     elif self.pivot[:3] == 'tip':
         X = X - X[:, 3, npy.newaxis]  #numpy bug? using -= does not
         # work here unless we multiply
         # by a float first, as with 'mid'.
     tooshort = length < self.minlength
     if tooshort.any():
         # Use a heptagonal dot:
         th = npy.arange(0, 7, 1, npy.float64) * (npy.pi / 3.0)
         x1 = npy.cos(th) * self.minlength * 0.5
         y1 = npy.sin(th) * self.minlength * 0.5
         X1 = npy.repeat(x1[npy.newaxis, :], N, axis=0)
         Y1 = npy.repeat(y1[npy.newaxis, :], N, axis=0)
         tooshort = ma.repeat(tooshort, 7, 1)
         X = ma.where(tooshort, X1, X)
         Y = ma.where(tooshort, Y1, Y)
     return X, Y
示例#2
0
文件: quiver.py 项目: gkliska/razvoj
 def _h_arrows(self, length):
     """ length is in arrow width units """
     # It might be possible to streamline the code
     # and speed it up a bit by using complex (x,y)
     # instead of separate arrays; but any gain would be slight.
     minsh = self.minshaft * self.headlength
     N = len(length)
     length = length.reshape(N, 1)
     # x, y: normal horizontal arrow
     x = npy.array([0, -self.headaxislength,
                     -self.headlength, 0], npy.float64)
     x = x + npy.array([0,1,1,1]) * length
     y = 0.5 * npy.array([1, 1, self.headwidth, 0], npy.float64)
     y = npy.repeat(y[npy.newaxis,:], N, axis=0)
     # x0, y0: arrow without shaft, for short vectors
     x0 = npy.array([0, minsh-self.headaxislength,
                     minsh-self.headlength, minsh], npy.float64)
     y0 = 0.5 * npy.array([1, 1, self.headwidth, 0], npy.float64)
     ii = [0,1,2,3,2,1,0]
     X = x.take(ii, 1)
     Y = y.take(ii, 1)
     Y[:, 3:] *= -1
     X0 = x0.take(ii)
     Y0 = y0.take(ii)
     Y0[3:] *= -1
     shrink = length/minsh
     X0 = shrink * X0[npy.newaxis,:]
     Y0 = shrink * Y0[npy.newaxis,:]
     short = npy.repeat(length < minsh, 7, axis=1)
     #print 'short', length < minsh
     # Now select X0, Y0 if short, otherwise X, Y
     X = ma.where(short, X0, X)
     Y = ma.where(short, Y0, Y)
     if self.pivot[:3] == 'mid':
         X -= 0.5 * X[:,3, npy.newaxis]
     elif self.pivot[:3] == 'tip':
         X = X - X[:,3, npy.newaxis]   #numpy bug? using -= does not
                                      # work here unless we multiply
                                      # by a float first, as with 'mid'.
     tooshort = length < self.minlength
     if tooshort.any():
         # Use a heptagonal dot:
         th = npy.arange(0,7,1, npy.float64) * (npy.pi/3.0)
         x1 = npy.cos(th) * self.minlength * 0.5
         y1 = npy.sin(th) * self.minlength * 0.5
         X1 = npy.repeat(x1[npy.newaxis, :], N, axis=0)
         Y1 = npy.repeat(y1[npy.newaxis, :], N, axis=0)
         tooshort = ma.repeat(tooshort, 7, 1)
         X = ma.where(tooshort, X1, X)
         Y = ma.where(tooshort, Y1, Y)
     return X, Y
示例#3
0
 def transform(self, a):
     sign = npy.sign(npy.asarray(a))
     masked = ma.masked_inside(a, -self.linthresh, self.linthresh, copy=False)
     log = sign * ma.log(npy.abs(masked)) / self._log_base
     if masked.mask.any():
         return npy.asarray(ma.where(masked.mask,
                                     a * self._linadjust,
                                     log))
     else:
         return npy.asarray(log)