[Python-modules-commits] [python-mplexporter] 108/135: recursive drawing of legend

Wolfgang Borgert debacle at moszumanska.debian.org
Tue Sep 23 21:19:09 UTC 2014


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to branch master
in repository python-mplexporter.

commit 5231e41af3d69c755956a45e11938d7b6d16798b
Author: John Eppley <jmeppley at gmail.com>
Date:   Wed Mar 26 10:36:31 2014 -0400

    recursive drawing of legend
---
 mplexporter/exporter.py | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/mplexporter/exporter.py b/mplexporter/exporter.py
index 515c6af..907cf05 100644
--- a/mplexporter/exporter.py
+++ b/mplexporter/exporter.py
@@ -146,20 +146,32 @@ class Exporter(object):
                     if props['visible']:
                         self.crawl_legend(ax, legend)
 
-    def crawl_legend(self, ax, legend):
-        for child in legend.get_children():
+    def crawl_legend(self, ax, obj, used_objects=set()):
+        """
+        Recursively look through objects in legend children
+        """
+        for child in obj.get_children():
+            # skip things we've alread drawn
+            if child in used_objects:
+                continue
+            else:
+                used_objects.add(child)
+
             # force a large zorder so it appears on top
             child.set_zorder(1E6 + child.get_zorder())
+
+            # What kind of object...
             if isinstance(child, matplotlib.patches.Patch):
                 self.draw_patch(ax, child, force_trans=ax.transAxes)
             elif isinstance(child, matplotlib.text.Text):
-                if not (child is legend.get_children()[-1]
+                if not (child is obj.get_children()[-1]
                         and child.get_text() == 'None'):
                     self.draw_text(ax, child, force_trans=ax.transAxes)
             elif isinstance(child, matplotlib.lines.Line2D):
                 self.draw_line(ax, child, force_trans=ax.transAxes)
-            elif isinstance(child, matplotlib.offsetbox.PackerBase):
-                pass
+            elif child.get_children() is not None \
+                    and len(child.get_children())>0:
+                self.crawl_legend(ax, child, used_objects=used_objects)
             else:
                 warnings.warn("Legend element %s not impemented" & child)
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-mplexporter.git



More information about the Python-modules-commits mailing list