def imshow(self, color, luminosity=None, ax=None, **kwargs): """ shows an image on ax. always expecting color and luminosity normalized to [0, 1]. Notice that the convention of axes is different from pyplot.imshow. Here the first dimension is the horizontal and the second dimension is the vertical. Notice that the origin is also at the lower(thus a traditional x, y plot), rather than upper as in pyplot.imshow The default color map is coolwarm if luminosity is given gist_heat if luminosity is not given Example: >> C, L = paint('ie', 'mass') >> imshow(nl_(C), nl_(L)) """ if ax is None: ax = self.default_axes realkwargs = dict(origin='lower', extent=self.extent) if luminosity is not None: realkwargs['cmap'] = cm.coolwarm else: realkwargs['cmap'] = cm.gist_heat realkwargs.update(kwargs) self.last['cmap'] = realkwargs['cmap'] cmap = realkwargs['cmap'] if len(color.shape) < 3: if not isinstance(color, normalize): color = n_(color) if luminosity is not None and not isinstance( luminosity, normalize): luminosity = n_(luminosity) im = self.image(color=color, luminosity=luminosity, cmap=cmap) else: im = color ret = ax.imshow(im.swapaxes(0, 1), **realkwargs) self.last['color'] = color return ret
def imshow(self, color, luminosity=None, ax=None, **kwargs): """ shows an image on ax. always expecting color and luminosity normalized to [0, 1]. Notice that the convention of axes is different from pyplot.imshow. Here the first dimension is the horizontal and the second dimension is the vertical. Notice that the origin is also at the lower(thus a traditional x, y plot), rather than upper as in pyplot.imshow The default color map is coolwarm if luminosity is given gist_heat if luminosity is not given Example: >> C, L = paint('ie', 'mass') >> imshow(nl_(C), nl_(L)) """ if ax is None: ax=self.default_axes realkwargs = dict(origin='lower', extent=self.extent) if luminosity is not None: realkwargs['cmap'] = cm.coolwarm else: realkwargs['cmap'] = cm.gist_heat realkwargs.update(kwargs) self.last['cmap'] = realkwargs['cmap'] cmap = realkwargs['cmap'] if len(color.shape) < 3: if not isinstance(color, normalize): color = n_(color) if luminosity is not None and not isinstance(luminosity, normalize): luminosity = n_(luminosity) im = self.image(color=color, luminosity=luminosity, cmap=cmap) else: im = color ret = ax.imshow(im.swapaxes(0,1), **realkwargs) self.last['color'] = color return ret
def drawbox(self, center, size, color=[0, 1., 0], ax=None): if ax is None: ax = self.default_axes center = numpy.asarray(center) color = numpy.asarray(color, dtype='f8') bbox = (numpy.mgrid[0:2, 0:2, 0:2].reshape(3, -1).T - 0.5) * size \ + center[None, :] X, Y, B = self.transform(bbox, numpy.ones(len(bbox)), radius=None) l, r, b, t = self.extent X = X / self.shape[0] * (r - l) + l Y = Y / self.shape[1] * (t - b) + b pairs = ((0, 1), (2, 3), (6, 7), (4, 5), (1, 5), (5, 7), (7, 3), (3, 1), (0, 4), (4, 6), (6, 2), (2, 0)) lines = [((X[a], Y[a]), (X[b], Y[b])) for a, b in pairs] colors = numpy.ones((len(lines), 4)) colors[:, 0:3] *= color colors[:, 3] *= n_([B[a] + B[b] for a, b in pairs]) * 0.7 + 0.3 ax.add_collection( LineCollection(lines, linewidth=0.5, colors=colors, antialiased=1))
def drawbox(self, center, size, color=[0, 1., 0], ax=None): if ax is None: ax=self.default_axes center = numpy.asarray(center) color = numpy.asarray(color, dtype='f8') bbox = (numpy.mgrid[0:2, 0:2, 0:2].reshape(3, -1).T - 0.5) * size \ + center[None, :] X, Y, B = self.transform(bbox, numpy.ones(len(bbox)), radius=None) l, r, b, t = self.extent X = X / self.shape[0] * (r - l) + l Y = Y / self.shape[1] * (t - b) + b pairs = ((0,1), (2,3), (6,7), (4,5), (1,5), (5,7), (7,3), (3,1), (0,4), (4,6), (6,2), (2,0)) lines = [((X[a], Y[a]), (X[b], Y[b])) for a, b in pairs] colors = numpy.ones((len(lines), 4)) colors[:, 0:3] *= color colors[:, 3] *= n_([B[a] + B[b] for a, b in pairs]) * 0.7 + 0.3 ax.add_collection(LineCollection(lines, linewidth=0.5, colors=colors, antialiased=1))