Beispiel #1
0
    def draw(self, renderer):
        """
        Render the figure using :class:`matplotlib.backend_bases.RendererBase` instance renderer
        """
        # draw the figure bounding box, perhaps none for white figure
        if not self.get_visible(): return
        renderer.open_group('figure')

        if self.frameon: self.patch.draw(renderer)

        # a list of (zorder, func_to_call, list_of_args)
        dsu = []

        for a in self.patches:
            dsu.append((a.get_zorder(), a.draw, [renderer]))

        for a in self.lines:
            dsu.append((a.get_zorder(), a.draw, [renderer]))

        for a in self.artists:
            dsu.append((a.get_zorder(), a.draw, [renderer]))

        # override the renderer default if self.suppressComposite
        # is not None
        not_composite = renderer.option_image_nocomposite()
        if self.suppressComposite is not None:
            not_composite = self.suppressComposite

        if len(self.images)<=1 or not_composite or \
                not allequal([im.origin for im in self.images]):
            for a in self.images:
                dsu.append((a.get_zorder(), a.draw, [renderer]))
        else:
            # make a composite image blending alpha
            # list of (_image.Image, ox, oy)
            mag = renderer.get_image_magnification()
            ims = [(im.make_image(mag), im.ox, im.oy) for im in self.images]

            im = _image.from_images(self.bbox.height * mag,
                                    self.bbox.width * mag, ims)

            im.is_grayscale = False
            l, b, w, h = self.bbox.bounds

            def draw_composite():
                gc = renderer.new_gc()
                gc.set_clip_rectangle(self.bbox)
                gc.set_clip_path(self.get_clip_path())
                renderer.draw_image(gc, l, b, im)
                gc.restore()

            dsu.append((self.images[0].get_zorder(), draw_composite, []))

        # render the axes
        for a in self.axes:
            dsu.append((a.get_zorder(), a.draw, [renderer]))

        # render the figure text
        for a in self.texts:
            dsu.append((a.get_zorder(), a.draw, [renderer]))

        for a in self.legends:
            dsu.append((a.get_zorder(), a.draw, [renderer]))

        dsu.sort(key=itemgetter(0))
        for zorder, func, args in dsu:
            func(*args)

        renderer.close_group('figure')

        self._cachedRenderer = renderer

        self.canvas.draw_event(renderer)
Beispiel #2
0
    def draw(self, renderer):
        """
        Render the figure using :class:`matplotlib.backend_bases.RendererBase` instance renderer
        """
        # draw the figure bounding box, perhaps none for white figure
        if not self.get_visible(): return
        renderer.open_group('figure')

        if self.frameon: self.patch.draw(renderer)

        # a list of (zorder, func_to_call, list_of_args)
        dsu = []

        for a in self.patches:
            dsu.append( (a.get_zorder(), a.draw, [renderer]))

        for a in self.lines:
            dsu.append( (a.get_zorder(), a.draw, [renderer]))

        for a in self.artists:
            dsu.append( (a.get_zorder(), a.draw, [renderer]))

        # override the renderer default if self.suppressComposite
        # is not None
        not_composite = renderer.option_image_nocomposite()
        if self.suppressComposite is not None:
            not_composite = self.suppressComposite

        if len(self.images)<=1 or not_composite or \
                not allequal([im.origin for im in self.images]):
            for a in self.images:
                dsu.append( (a.get_zorder(), a.draw, [renderer]))
        else:
            # make a composite image blending alpha
            # list of (_image.Image, ox, oy)
            mag = renderer.get_image_magnification()
            ims = [(im.make_image(mag), im.ox, im.oy)
                   for im in self.images]

            im = _image.from_images(self.bbox.height * mag,
                                    self.bbox.width * mag,
                                    ims)

            im.is_grayscale = False
            l, b, w, h = self.bbox.bounds

            def draw_composite():
                gc = renderer.new_gc()
                gc.set_clip_rectangle(self.bbox)
                gc.set_clip_path(self.get_clip_path())
                renderer.draw_image(gc, l, b, im)
                gc.restore()

            dsu.append((self.images[0].get_zorder(), draw_composite, []))

        # render the axes
        for a in self.axes:
            dsu.append( (a.get_zorder(), a.draw, [renderer]))

        # render the figure text
        for a in self.texts:
            dsu.append( (a.get_zorder(), a.draw, [renderer]))

        for a in self.legends:
            dsu.append( (a.get_zorder(), a.draw, [renderer]))

        dsu.sort(key=itemgetter(0))
        for zorder, func, args in dsu:
            func(*args)

        renderer.close_group('figure')

        self._cachedRenderer = renderer

        self.canvas.draw_event(renderer)