Exemple #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
        #print 'figure draw'
        if not self.get_visible(): return
        renderer.open_group('figure')

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

        # todo: respect zorder
        for p in self.patches:
            p.draw(renderer)
        for l in self.lines:
            l.draw(renderer)
        for a in self.artists:
            a.draw(renderer)

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

        if len(self.images) <= 1 or composite or not allequal(
            [im.origin for im in self.images]):
            for im in self.images:
                im.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 * mag, im.oy * mag)
                   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
            clippath, affine = self.get_transformed_clip_path_and_affine()
            renderer.draw_image(l, b, im, self.bbox, clippath, affine)

        # render the axes
        for a in self.axes:
            a.draw(renderer)

        # render the figure text
        for t in self.texts:
            t.draw(renderer)

        for legend in self.legends:
            legend.draw(renderer)

        renderer.close_group('figure')

        self._cachedRenderer = renderer

        self.canvas.draw_event(renderer)
Exemple #2
0
 def draw(self, renderer):
     """
     Render the figure using :class:`matplotlib.backend_bases.RendererBase` instance renderer
     """
     if not self.get_visible(): return
     renderer.open_group('figure')
     if self.frameon: self.patch.draw(renderer)
     for p in self.patches: p.draw(renderer)
     for l in self.lines: l.draw(renderer)
     for a in self.artists: a.draw(renderer)
     composite = renderer.option_image_nocomposite()
     if self.suppressComposite is not None:
         composite = self.suppressComposite
     if len(self.images)<=1 or composite or not allequal([im.origin for im in self.images]):
         for im in self.images:
             im.draw(renderer)
     else:
         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
         clippath, affine = self.get_transformed_clip_path_and_affine()
         renderer.draw_image(l, b, im, self.bbox,
                             clippath, affine)
     for a in self.axes: a.draw(renderer)
     for t in self.texts: t.draw(renderer)
     for legend in self.legends:
         legend.draw(renderer)
     renderer.close_group('figure')
     self._cachedRenderer = renderer
     self.canvas.draw_event(renderer)
Exemple #3
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
        # print 'figure draw'
        if not self.get_visible():
            return
        renderer.open_group("figure")

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

        # todo: respect zorder
        for p in self.patches:
            p.draw(renderer)
        for l in self.lines:
            l.draw(renderer)
        for a in self.artists:
            a.draw(renderer)

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

        if len(self.images) <= 1 or composite or not allequal([im.origin for im in self.images]):
            for im in self.images:
                im.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
            clippath, affine = self.get_transformed_clip_path_and_affine()
            renderer.draw_image(l, b, im, self.bbox, clippath, affine)

        # render the axes
        for a in self.axes:
            a.draw(renderer)

        # render the figure text
        for t in self.texts:
            t.draw(renderer)

        for legend in self.legends:
            legend.draw(renderer)

        renderer.close_group("figure")

        self._cachedRenderer = renderer

        self.canvas.draw_event(renderer)
Exemple #4
0
    def draw(self, renderer):
        """
        Render the figure using Renderer instance renderer
        """
        # draw the figure bounding box, perhaps none for white figure
        #print 'figure draw'
        if not self.get_visible(): return
        renderer.open_group('figure')
        self.transFigure.freeze()  # eval the lazy objects

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

        for p in self.patches:
            p.draw(renderer)
        for l in self.lines:
            l.draw(renderer)

        if len(self.images) <= 1 or renderer.option_image_nocomposite(
        ) or not allequal([im.origin for im in self.images]):
            for im in self.images:
                im.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 * mag, im.oy * mag)
                   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.get_bounds()
            renderer.draw_image(l, b, im, self.bbox)

        # render the axes
        for a in self.axes:
            a.draw(renderer)

        # render the figure text
        for t in self.texts:
            t.draw(renderer)

        for legend in self.legends:
            legend.draw(renderer)

        self.transFigure.thaw()  # release the lazy objects
        renderer.close_group('figure')

        self._cachedRenderer = renderer

        self.canvas.draw_event(renderer)
Exemple #5
0
    def draw(self, renderer):
        """
        Render the figure using RendererGD instance renderer
        """
        # draw the figure bounding box, perhaps none for white figure
        # print 'figure draw'
        if not self.get_visible():
            return
        renderer.open_group("figure")
        self.transFigure.freeze()  # eval the lazy objects

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

        for p in self.patches:
            p.draw(renderer)
        for l in self.lines:
            l.draw(renderer)

        if len(self.images) == 1:
            im = self.images[0]
            im.draw(renderer)
        elif len(self.images) > 1:
            # make a composite image blending alpha
            # list of (_image.Image, ox, oy)
            if not allequal([im.origin for im in self.images]):
                raise ValueError("Composite images with different origins not supported")
            ims = [(im.make_image(), im.ox, im.oy) for im in self.images]
            im = _image.from_images(self.bbox.height(), self.bbox.width(), ims)
            im.is_grayscale = False
            l, b, w, h = self.bbox.get_bounds()
            renderer.draw_image(0, 0, im, self.bbox)

        # render the axes
        for a in self.axes:
            a.draw(renderer)

        # render the figure text
        for t in self.texts:
            t.draw(renderer)

        for legend in self.legends:
            legend.draw(renderer)

        self.transFigure.thaw()  # release the lazy objects
        renderer.close_group("figure")

        self._cachedRenderer = renderer

        self.canvas.draw_event(renderer)
Exemple #6
0
    def draw(self, renderer):
        """
        Render the figure using Renderer instance renderer
        """
        # draw the figure bounding box, perhaps none for white figure
        #print 'figure draw'
        if not self.get_visible(): return
        renderer.open_group('figure')
        self.transFigure.freeze()  # eval the lazy objects

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

        for p in self.patches:
            p.draw(renderer)
        for l in self.lines:
            l.draw(renderer)

        if len(self.images) == 1:
            im = self.images[0]
            im.draw(renderer)
        elif len(self.images) > 1:
            # make a composite image blending alpha
            # list of (_image.Image, ox, oy)
            if not allequal([im.origin for im in self.images]):
                raise ValueError(
                    'Composite images with different origins not supported')
            ims = [(im.make_image(), im.ox, im.oy) for im in self.images]
            im = _image.from_images(self.bbox.height(), self.bbox.width(), ims)
            im.is_grayscale = False
            l, b, w, h = self.bbox.get_bounds()
            renderer.draw_image(0, 0, im, self.bbox)

        # render the axes
        for a in self.axes:
            a.draw(renderer)

        # render the figure text
        for t in self.texts:
            t.draw(renderer)

        for legend in self.legends:
            legend.draw(renderer)

        self.transFigure.thaw()  # release the lazy objects
        renderer.close_group('figure')

        self._cachedRenderer = renderer

        self.canvas.draw_event(renderer)
Exemple #7
0
 def draw(self, renderer):
     """
     Render the figure using :class:`matplotlib.backend_bases.RendererBase` instance renderer
     """
     if not self.get_visible(): return
     renderer.open_group('figure')
     if self.frameon: self.patch.draw(renderer)
     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]))
     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:
         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, []))
     for a in self.axes:
         dsu.append( (a.get_zorder(), a.draw, [renderer]))
     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)
Exemple #8
0
    def draw(self, renderer):
        """
        Render the figure using Renderer instance renderer
        """
        # draw the figure bounding box, perhaps none for white figure
        #print 'figure draw'
        if not self.get_visible(): return
        renderer.open_group('figure')
        self.transFigure.freeze()  # eval the lazy objects

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

        for p in self.patches: p.draw(renderer)
        for l in self.lines: l.draw(renderer)

        if len(self.images)<=1 or renderer.option_image_nocomposite() or not allequal([im.origin for im in self.images]):
            for im in self.images:
                im.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*mag, im.oy*mag)
                   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.get_bounds()
            renderer.draw_image(l, b, im, self.bbox)


        # render the axes
        for a in self.axes: a.draw(renderer)

        # render the figure text
        for t in self.texts: t.draw(renderer)

        for legend in self.legends:
            legend.draw(renderer)

        self.transFigure.thaw()  # release the lazy objects
        renderer.close_group('figure')

        self._cachedRenderer = renderer

        self.canvas.draw_event(renderer)
Exemple #9
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, a.draw, [renderer]))

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

        for a in self.artists:
            dsu.append( (a.get_zorder(), a, 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, 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(), self.images[0], draw_composite, []))

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

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

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

        dsu = [row for row in dsu if not row[1].get_animated()]
        dsu.sort(key=itemgetter(0))
        for zorder, a, func, args in dsu:
            func(*args)

        renderer.close_group('figure')

        self._cachedRenderer = renderer

        self.canvas.draw_event(renderer)
Exemple #10
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)
Exemple #11
0
    def draw(self, renderer):
        """
        Render the figure using Renderer instance renderer
        """
        # draw the figure bounding box, perhaps none for white figure
        #print 'figure draw'
        if not self.get_visible(): return
        renderer.open_group('figure')

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

        for p in self.patches:
            p.draw(renderer)
        for l in self.lines:
            l.draw(renderer)

        if len(self.images) <= 1 or renderer.option_image_nocomposite(
        ) or not allequal([im.origin for im in self.images]):
            for im in self.images:
                im.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 * mag, im.oy * mag)
                   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
            renderer.draw_image(l, b, im, self.bbox,
                                *self.get_transformed_clip_path_and_affine())

        # update the positions of the axes
        # This gives each of the axes the opportunity to resize itself
        # based on the tick and axis labels etc., and then makes sure
        # that any axes that began life aligned to another axes remains
        # aligned after these adjustments
        if self._autoLayout and len(self.axes) > 1:
            aligned_positions = [{}, {}, {}, {}]
            sizes = [{}, {}]
            for a in self.axes:
                a.update_layout(renderer)
                orig_pos = a.get_position(True)
                curr_pos = a.get_position()
                for pos, orig, curr in zip(aligned_positions,
                                           orig_pos.get_points().flatten(),
                                           curr_pos.get_points().flatten()):
                    if orig in pos:
                        pos[orig][0].append(a)
                        pos[orig][1].add(curr)
                    else:
                        pos[orig] = [[a], set([curr])]
                for size, orig, curr in zip(sizes, orig_pos.size,
                                            curr_pos.size):
                    orig = round(orig * 1000.0) / 1000.0
                    if orig in size:
                        size[orig][0].append(a)
                        size[orig][1].add(curr)
                    else:
                        size[orig] = [[a], set([curr])]

            for i, pos in enumerate(aligned_positions):
                for axes, places in pos.values():
                    if len(places) > 1:
                        if i < 2:
                            curr = max(places)
                        else:
                            curr = min(places)
                        for a in axes:
                            curr_pos = a.get_position().frozen()
                            curr_pos.get_points()[i / 2, i % 2] = curr
                            a.set_position(curr_pos, 'active')

            for i, size in enumerate(sizes):
                for axes, dims in size.values():
                    new = min(dims)
                    for a in axes:
                        curr_pos = a.get_position().frozen()
                        curr = curr_pos.size[i]
                        if curr > new:
                            extra = (curr - new) * 0.5
                            curr_pos.get_points()[0, i] += extra
                            curr_pos.get_points()[1, i] -= extra
                            a.set_position(curr_pos, 'active')
        elif self._autoLayout:
            for a in self.axes:
                a.update_layout(renderer)

        # render the axes
        for a in self.axes:
            a.draw(renderer)

        # render the figure text
        for t in self.texts:
            t.draw(renderer)

        for legend in self.legends:
            legend.draw(renderer)

        renderer.close_group('figure')

        self._cachedRenderer = renderer

        self.canvas.draw_event(renderer)
Exemple #12
0
    def draw(self, renderer):
        """
        Render the figure using Renderer instance renderer
        """
        # draw the figure bounding box, perhaps none for white figure
        #print 'figure draw'
        if not self.get_visible(): return
        renderer.open_group('figure')

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

        for p in self.patches: p.draw(renderer)
        for l in self.lines: l.draw(renderer)

        if len(self.images)<=1 or renderer.option_image_nocomposite() or not allequal([im.origin for im in self.images]):
            for im in self.images:
                im.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*mag, im.oy*mag)
                   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
            renderer.draw_image(l, b, im, self.bbox,
                                *self.get_transformed_clip_path_and_affine())

        # update the positions of the axes
        # This gives each of the axes the opportunity to resize itself
        # based on the tick and axis labels etc., and then makes sure
        # that any axes that began life aligned to another axes remains
        # aligned after these adjustments
        if self._autoLayout and len(self.axes) > 1:
            aligned_positions = [{}, {}, {}, {}]
            sizes = [{}, {}]
            for a in self.axes:
                a.update_layout(renderer)
                orig_pos = a.get_position(True)
                curr_pos = a.get_position()
                for pos, orig, curr in zip(aligned_positions,
                                           orig_pos.get_points().flatten(),
                                           curr_pos.get_points().flatten()):
                    if orig in pos:
                        pos[orig][0].append(a)
                        pos[orig][1].add(curr)
                    else:
                        pos[orig] = [[a], set([curr])]
                for size, orig, curr in zip(sizes,
                                            orig_pos.size,
                                            curr_pos.size):
                    orig = round(orig * 1000.0) / 1000.0
                    if orig in size:
                        size[orig][0].append(a)
                        size[orig][1].add(curr)
                    else:
                        size[orig] = [[a], set([curr])]

            for i, pos in enumerate(aligned_positions):
                for axes, places in pos.values():
                    if len(places) > 1:
                        if i < 2:
                            curr = max(places)
                        else:
                            curr = min(places)
                        for a in axes:
                            curr_pos = a.get_position().frozen()
                            curr_pos.get_points()[i/2, i%2] = curr
                            a.set_position(curr_pos, 'active')

            for i, size in enumerate(sizes):
                for axes, dims in size.values():
                    new = min(dims)
                    for a in axes:
                        curr_pos = a.get_position().frozen()
                        curr = curr_pos.size[i]
                        if curr > new:
                            extra = (curr - new) * 0.5
                            curr_pos.get_points()[0, i] += extra
                            curr_pos.get_points()[1, i] -= extra
                            a.set_position(curr_pos, 'active')
        elif self._autoLayout:
            for a in self.axes: a.update_layout(renderer)

        # render the axes
        for a in self.axes: a.draw(renderer)

        # render the figure text
        for t in self.texts: t.draw(renderer)

        for legend in self.legends:
            legend.draw(renderer)

        renderer.close_group('figure')

        self._cachedRenderer = renderer

        self.canvas.draw_event(renderer)