Beispiel #1
0
 def _outline(self, X, Y):
     """
     Return x, y arrays of colorbar bounding polygon,
     taking orientation into account.
     """
     N = nx.shape(X)[0]
     ii = [0, 1, N - 2, N - 1, 2 * N - 1, 2 * N - 2, N + 1, N, 0]
     x = nx.take(nx.ravel(nx.transpose(X)), ii)
     y = nx.take(nx.ravel(nx.transpose(Y)), ii)
     if self.orientation == "horizontal":
         return y, x
     return x, y
Beispiel #2
0
 def _outline(self, X, Y):
     '''
     Return x, y arrays of colorbar bounding polygon,
     taking orientation into account.
     '''
     N = nx.shape(X)[0]
     ii = [0, 1, N - 2, N - 1, 2 * N - 1, 2 * N - 2, N + 1, N, 0]
     x = nx.take(nx.ravel(nx.transpose(X)), ii)
     y = nx.take(nx.ravel(nx.transpose(Y)), ii)
     if self.orientation == 'horizontal':
         return y, x
     return x, y
Beispiel #3
0
 def _h_arrows(self, length):
     ''' length is in arrow width units '''
     minsh = self.minshaft * self.headlength
     N = len(length)
     length = nx.reshape(length, (N,1))
     x = nx.array([0, -self.headaxislength,
                     -self.headlength, 0], nx.Float64)
     x = x + nx.array([0,1,1,1]) * length
     y = 0.5 * nx.array([1, 1, self.headwidth, 0], nx.Float64)
     y = nx.repeat(y[nx.newaxis,:], N)
     x0 = nx.array([0, minsh-self.headaxislength,
                     minsh-self.headlength, minsh], nx.Float64)
     y0 = 0.5 * nx.array([1, 1, self.headwidth, 0], nx.Float64)
     ii = [0,1,2,3,2,1,0]
     X = nx.take(x, ii, 1)
     Y = nx.take(y, ii, 1)
     Y[:, 3:] *= -1
     X0 = nx.take(x0, ii)
     Y0 = nx.take(y0, ii)
     Y0[3:] *= -1
     shrink = length/minsh
     X0 = shrink * X0[nx.newaxis,:]
     Y0 = shrink * Y0[nx.newaxis,:]
     short = nx.repeat(length < minsh, 7, 1)
     #print 'short', length < minsh
     X = nx.where(short, X0, X)
     Y = nx.where(short, Y0, Y)
     if self.pivot[:3] == 'mid':
         X -= 0.5 * X[:,3, nx.newaxis]
     elif self.pivot[:3] == 'tip':
         X = X - X[:,3, nx.newaxis]   #numpy bug? using -= does not
                                      # work here unless we multiply
                                      # by a float first, as with 'mid'.
     tooshort = length < self.minlength
     if nx.any(tooshort):
         th = nx.arange(0,7,1, nx.Float64) * (nx.pi/3.0)
         x1 = nx.cos(th) * self.minlength * 0.5
         y1 = nx.sin(th) * self.minlength * 0.5
         X1 = nx.repeat(x1[nx.newaxis, :], N, 0)
         Y1 = nx.repeat(y1[nx.newaxis, :], N, 0)
         tooshort = nx.repeat(tooshort, 7, 1)
         X = nx.where(tooshort, X1, X)
         Y = nx.where(tooshort, Y1, Y)
     return X, Y
Beispiel #4
0
 def _locate(self, x):
     """
     Return the colorbar data coordinate(s) corresponding to the color
     value(s) in scalar or array x.
     Used for tick positioning.
     """
     b = self._boundaries
     y = self._y
     N = len(b)
     ii = nx.minimum(nx.searchsorted(b, x), N - 1)
     isscalar = False
     if not iterable(ii):
         isscalar = True
         ii = nx.array((ii,))
     i0 = nx.maximum(ii - 1, 0)
     # db = b[ii] - b[i0]
     db = nx.take(b, ii) - nx.take(b, i0)
     db = nx.where(i0 == ii, 1.0, db)
     # dy = y[ii] - y[i0]
     dy = nx.take(y, ii) - nx.take(y, i0)
     z = nx.take(y, i0) + (x - nx.take(b, i0)) * dy / db
     if isscalar:
         z = z[0]
     return z
Beispiel #5
0
 def _locate(self, x):
     '''
     Return the colorbar data coordinate(s) corresponding to the color
     value(s) in scalar or array x.
     Used for tick positioning.
     '''
     b = self._boundaries
     y = self._y
     N = len(b)
     ii = nx.minimum(nx.searchsorted(b, x), N - 1)
     isscalar = False
     if not iterable(ii):
         isscalar = True
         ii = nx.array((ii, ))
     i0 = nx.maximum(ii - 1, 0)
     #db = b[ii] - b[i0]
     db = nx.take(b, ii) - nx.take(b, i0)
     db = nx.where(i0 == ii, 1.0, db)
     #dy = y[ii] - y[i0]
     dy = nx.take(y, ii) - nx.take(y, i0)
     z = nx.take(y, i0) + (x - nx.take(b, i0)) * dy / db
     if isscalar:
         z = z[0]
     return z