Beispiel #1
0
    def OnWhiz(self, evt):
        self.x += numerix.pi / 15
        self.y += numerix.pi / 20
        z = numerix.sin(self.x) + numerix.cos(self.y)
        self.im.set_array(z)

        zmax = numerix.max(numerix.max(z)) - ERR_TOL
        ymax_i, xmax_i = numerix.nonzero(numerix.greater_equal(z, zmax))
        if self.im.origin == 'upper':
            ymax_i = z.shape[0] - ymax_i
        self.lines[0].set_data(xmax_i, ymax_i)

        self.canvas.draw()
Beispiel #2
0
    def OnWhiz(self,evt):
        self.x += numerix.pi/15
        self.y += numerix.pi/20
        z = numerix.sin(self.x) + numerix.cos(self.y)
        self.im.set_array(z)

        zmax = numerix.max(numerix.max(z))-ERR_TOL
        ymax_i, xmax_i = numerix.nonzero(
            numerix.greater_equal(z, zmax))
        if self.im.origin == 'upper':
            ymax_i = z.shape[0]-ymax_i
        self.lines[0].set_data(xmax_i,ymax_i)

        self.canvas.draw()
Beispiel #3
0
    def init_plot_data(self):
        a = self.fig.add_subplot(111)
        
        x = numerix.arange(120.0)*2*numerix.pi/60.0
        y = numerix.arange(100.0)*2*numerix.pi/50.0
        self.x, self.y = meshgrid(x, y)
        z = numerix.sin(self.x) + numerix.cos(self.y)
        self.im = a.imshow( z, cmap=cm.jet)#, interpolation='nearest')
        
        zmax = numerix.max(numerix.max(z))-ERR_TOL
        ymax_i, xmax_i = numerix.nonzero(
            numerix.greater_equal(z, zmax))
        if self.im.origin == 'upper':
            ymax_i = z.shape[0]-ymax_i
        self.lines = a.plot(xmax_i,ymax_i,'ko')

        self.toolbar.update() # Not sure why this is needed - ADS
Beispiel #4
0
    def _draw_mathtext(self, gc, x, y, s, prop, angle):
        if DEBUG: print 'backend_cairo.RendererCairo.%s()' % _fn_name()
        # mathtext using the gtk/gdk method

        try:
            import cairo.numpy
        except:
            verbose.report_error(
                "cairo.numpy module required for _draw_mathtext()")
            return

        size = prop.get_size_in_points()
        width, height, fonts = math_parse_s_ft2font(s, self.dpi.get(), size)

        if angle == 90:
            width, height = height, width
            x -= width
        y -= height

        imw, imh, s = fonts[0].image_as_str()
        N = imw * imh

        # a numpixels by num fonts array
        Xall = zeros((N, len(fonts)), typecode=UInt8)

        for i, font in enumerate(fonts):
            if angle == 90:
                font.horiz_image_to_vert_image()  # <-- Rotate
            imw, imh, s = font.image_as_str()
            Xall[:, i] = fromstring(s, UInt8)

        # get the max alpha at each pixel
        Xs = numerix.max(Xall, 1)

        # convert it to it's proper shape
        Xs.shape = imh, imw

        pa = zeros(shape=(imh, imw, 4), typecode=UInt8)
        rgb = gc.get_rgb()
        pa[:, :, 0] = int(rgb[0] * 255)
        pa[:, :, 1] = int(rgb[1] * 255)
        pa[:, :, 2] = int(rgb[2] * 255)
        pa[:, :, 3] = Xs

        surface = cairo.numpy.surface_create_for_array(pa)
        gc.ctx.translate(x, y)
        gc.ctx.show_surface(surface, imw, imh)
Beispiel #5
0
    def _draw_mathtext(self, gc, x, y, s, prop, angle):
        if DEBUG: print 'backend_cairo.RendererCairo.%s()' % _fn_name()
       # mathtext using the gtk/gdk method

        try: import cairo.numpy
        except:
            verbose.report_error("cairo.numpy module required for _draw_mathtext()")
            return

        size = prop.get_size_in_points()
        width, height, fonts = math_parse_s_ft2font(
            s, self.dpi.get(), size)

        if angle==90:
            width, height = height, width
            x -= width
        y -= height

        imw, imh, s = fonts[0].image_as_str()
        N = imw*imh

        # a numpixels by num fonts array
        Xall = zeros((N,len(fonts)), typecode=UInt8)

        for i, font in enumerate(fonts):
            if angle == 90:
                font.horiz_image_to_vert_image() # <-- Rotate
            imw, imh, s = font.image_as_str()
            Xall[:,i] = fromstring(s, UInt8)  

        # get the max alpha at each pixel
        Xs = numerix.max(Xall,1)

        # convert it to it's proper shape
        Xs.shape = imh, imw

        pa = zeros(shape=(imh,imw,4), typecode=UInt8)
        rgb = gc.get_rgb()
        pa[:,:,0] = int(rgb[0]*255)
        pa[:,:,1] = int(rgb[1]*255)
        pa[:,:,2] = int(rgb[2]*255)
        pa[:,:,3] = Xs

        surface = cairo.numpy.surface_create_for_array(pa)
        gc.ctx.translate (x,y)
        gc.ctx.show_surface (surface, imw, imh)
Beispiel #6
0
    def draw_mathtext(self, gc, x, y, s, prop, angle):

        size = prop.get_size_in_points()
        width, height, fonts = math_parse_s_ft2font(s, self.dpi.get(), size)

        if angle == 90:
            width, height = height, width
        x = int(x)
        y = int(y)

        rgb = gc.get_rgb()
        #rgba = (rgb[0], rgb[1], rgb[2], gc.get_alpha())

        imw, imh, s = fonts[0].image_as_str()
        N = imw * imh

        # a numpixels by num fonts array
        Xall = zeros((N, len(fonts)), typecode=UInt8)

        for i, font in enumerate(fonts):
            if angle == 90:
                font.horiz_image_to_vert_image()  # <-- Rotate
            imw, imh, s = font.image_as_str()
            Xall[:, i] = fromstring(s, UInt8)

        # get the max alpha at each pixel
        Xs = numerix.max(Xall, 1)

        # convert it to it's proper shape

        Xs.shape = imh, imw

        pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,
                            has_alpha=1,
                            bits_per_sample=8,
                            width=imw,
                            height=imh)

        try:
            pa = pb.get_pixels_array()
        except AttributeError:
            pa = pb.pixel_array
        except RuntimeError, exc:  #  pygtk was not compiled with Numeric Python support
            print >> sys.stderr, 'Error:', exc
            return
Beispiel #7
0
    def _draw_mathtext(self, gc, x, y, s, prop, angle):
        size = prop.get_size_in_points()
        width, height, fonts = math_parse_s_ft2font(s, self.dpi.get(), size)

        if angle == 90:
            width, height = height, width
            x -= width
        y -= height

        imw, imh, s = fonts[0].image_as_str()
        N = imw * imh

        # a numpixels by num fonts array
        Xall = zeros((N, len(fonts)), typecode=UInt8)

        for i, font in enumerate(fonts):
            if angle == 90:
                font.horiz_image_to_vert_image()  # <-- Rotate
            imw, imh, s = font.image_as_str()
            Xall[:, i] = fromstring(s, UInt8)

        # get the max alpha at each pixel
        Xs = numerix.max(Xall, 1)

        # convert it to it's proper shape
        Xs.shape = imh, imw

        pb = gtk.gdk.Pixbuf(
            gtk.gdk.COLORSPACE_RGB,
            #has_alpha=1, bits_per_sample=8, width=imw, height=imh)
            has_alpha=True,
            bits_per_sample=8,
            width=imw,
            height=imh)

        try:
            pa = pb.get_pixels_array()
        except AttributeError:
            pa = pb.pixel_array
        except RuntimeError, exc:  #  'pygtk was not compiled with Numeric Python support'
            verbose.report_error('mathtext not supported: %s' % exc)
            return
Beispiel #8
0
    def _draw_mathtext(self, gc, x, y, s, prop, angle):
        size = prop.get_size_in_points()
        width, height, fonts = math_parse_s_ft2font(
            s, self.dpi.get(), size)

        if angle==90:
            width, height = height, width
            x -= width
        y -= height
        
        imw, imh, s = fonts[0].image_as_str()
        N = imw*imh

        # a numpixels by num fonts array
        Xall = zeros((N,len(fonts)), typecode=UInt8)

        for i, font in enumerate(fonts):
            if angle == 90:
                font.horiz_image_to_vert_image() # <-- Rotate
            imw, imh, s = font.image_as_str()
            Xall[:,i] = fromstring(s, UInt8)  

        # get the max alpha at each pixel
        Xs = numerix.max(Xall,1)

        # convert it to it's proper shape
        Xs.shape = imh, imw

        pb=gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,
                          #has_alpha=1, bits_per_sample=8, width=imw, height=imh)
                          has_alpha=True, bits_per_sample=8, width=imw, height=imh)

        try:
            pa = pb.get_pixels_array()
        except AttributeError:
            pa = pb.pixel_array
        except RuntimeError, exc: #  'pygtk was not compiled with Numeric Python support'
            verbose.report_error('mathtext not supported: %s' % exc)
            return