[Python-modules-commits] [python-mplexporter] 16/135: add text handling

Wolfgang Borgert debacle at moszumanska.debian.org
Tue Sep 23 21:18:58 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 dbe936c8bc074c922d6303cc72ff26a7050537ce
Author: Jake Vanderplas <vanderplas at astro.washington.edu>
Date:   Wed Feb 19 12:23:10 2014 -0800

    add text handling
---
 mplexporter/exporter.py       | 19 +++++++++++++++++++
 mplexporter/renderers/base.py |  3 +++
 mplexporter/utils.py          | 13 +++++++++++++
 3 files changed, 35 insertions(+)

diff --git a/mplexporter/exporter.py b/mplexporter/exporter.py
index c636b7f..d918f5b 100644
--- a/mplexporter/exporter.py
+++ b/mplexporter/exporter.py
@@ -87,6 +87,7 @@ class Exporter(object):
                       'dynamic': ax.get_navigate()}
         with self.renderer.draw_axes(ax, properties):
             self._extract_lines(ax)
+            self._extract_texts(ax)
 
     def _extract_lines(self, ax):
         for line in ax.lines:
@@ -103,3 +104,21 @@ class Exporter(object):
                 self.renderer.draw_markers(data,
                                            coordinates=code,
                                            style=markerstyle)
+
+    def _extract_texts(self, ax):
+        for text in ax.texts:
+            # xlabel and ylabel are passed as arguments to the axes
+            # we don't want to pass them again here
+            if text is ax.get_xlabel():
+                continue
+            if text is ax.get_ylabel():
+                continue
+
+            content = text.get_text()
+            if content:
+                transform = text.get_transform()
+                position = text.get_position()
+                code, position = self._process_transform(transform, ax,
+                                                         position)
+                style = utils.get_text_style(text)
+                self.renderer.draw_text(content, position, code, style)
diff --git a/mplexporter/renderers/base.py b/mplexporter/renderers/base.py
index 044b265..eef8b68 100644
--- a/mplexporter/renderers/base.py
+++ b/mplexporter/renderers/base.py
@@ -77,3 +77,6 @@ class Renderer(object):
     def draw_markers(self, data, coordinates, style):
         raise NotImplementedError()
 
+    def draw_text(self, text, position, coordinates, style):
+        raise NotImplementedError()
+
diff --git a/mplexporter/utils.py b/mplexporter/utils.py
index 8f2c4a0..f332b8f 100644
--- a/mplexporter/utils.py
+++ b/mplexporter/utils.py
@@ -93,3 +93,16 @@ def get_marker_style(line):
     style['markerpath'] = SVG_path(markerstyle.get_path(),
                                    markertransform)
     return style
+
+def get_text_style(text):
+    """Return the text style dict for a text instance"""
+    style = {}
+    style['alpha'] = text.get_alpha()
+    if style['alpha'] is None:
+        style['alpha'] = 1
+    style['fontsize'] = text.get_size()
+    style['color'] = color_to_hex(text.get_color())
+    style['halign'] = text.get_horizontalalignment() # left, center, right
+    style['valign'] = text.get_verticalalignment() # baseline, center, top
+    style['rotation'] = text.get_rotation()
+    return style

-- 
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