[Python-modules-commits] [python-mplexporter] 06/135: add fig and ax properties

Wolfgang Borgert debacle at moszumanska.debian.org
Tue Sep 23 21:18:57 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 3ffc3f7e5672d790598cbbd17da34da3d0cefa08
Author: Jake Vanderplas <vanderplas at astro.washington.edu>
Date:   Mon Feb 17 08:43:56 2014 -0800

    add fig and ax properties
---
 mplexporter/exporter.py                   | 18 ++++++++++++++++--
 mplexporter/renderers/base.py             | 16 ++++++++++------
 mplexporter/renderers/example_renderer.py |  4 ++--
 mplexporter/renderers/vincent_renderer.py |  6 +++---
 4 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/mplexporter/exporter.py b/mplexporter/exporter.py
index e4a4545..445b879 100644
--- a/mplexporter/exporter.py
+++ b/mplexporter/exporter.py
@@ -66,12 +66,26 @@ class Exporter(object):
             return code            
 
     def _crawl_fig(self, fig):
-        with self.renderer.draw_figure(fig):
+        properties = {'figwidth': fig.get_figwidth(),
+                      'figheight': fig.get_figheight(),
+                      'dpi': fig.dpi}
+        with self.renderer.draw_figure(fig, properties):
             for ax in fig.axes:
                 self._crawl_ax(ax)
 
     def _crawl_ax(self, ax):
-        with self.renderer.draw_axes(ax):
+        properties = {'xlim': ax.get_xlim(),
+                      'ylim': ax.get_ylim(),
+                      'xlabel': ax.get_xlabel(),
+                      'ylabel': ax.get_ylabel(),
+                      'title': ax.get_title(),
+                      'bounds': ax.get_position().bounds,
+                      'xgrid': (ax.xaxis._gridOnMajor
+                                and ax.xaxis.get_gridlines()),
+                      'ygrid': (ax.yaxis._gridOnMajor
+                                and ax.yaxis.get_gridlines()),
+                      'dynamic': ax.get_navigate()}
+        with self.renderer.draw_axes(ax, properties):
             self._extract_lines(ax)
 
     def _extract_lines(self, ax):
diff --git a/mplexporter/renderers/base.py b/mplexporter/renderers/base.py
index 119ceb9..044b265 100644
--- a/mplexporter/renderers/base.py
+++ b/mplexporter/renderers/base.py
@@ -34,34 +34,38 @@ class Renderer(object):
         return self.ax_has_ygrid(self._current_ax)
 
     @contextmanager
-    def draw_figure(self, fig):
+    def draw_figure(self, fig, properties):
         if hasattr(self, "_current_fig") and self._current_fig is not None:
             warnings.warn("figure embedded in figure: something is wrong")
         self._current_fig = fig
-        self.open_figure(fig)
+        self._fig_properties = properties
+        self.open_figure(fig, properties)
         yield
         self.close_figure(fig)
         self._current_fig = None
+        self._fig_properties = {}
 
     @contextmanager
-    def draw_axes(self, ax):
+    def draw_axes(self, ax, properties):
         if hasattr(self, "_current_ax") and self._current_ax is not None:
             warnings.warn("axes embedded in axes: something is wrong")
         self._current_ax = ax
-        self.open_axes(ax)
+        self._ax_properties = properties
+        self.open_axes(ax, properties)
         yield
         self.close_axes(ax)
         self._current_ax = None
+        self._ax_properties = {}
 
     # Following are the functions which should be overloaded in subclasses
 
-    def open_figure(self, fig):
+    def open_figure(self, fig, properties):
         pass
 
     def close_figure(self, fig):
         pass
 
-    def open_axes(self, ax):
+    def open_axes(self, ax, properties):
         pass
 
     def close_axes(self, ax):
diff --git a/mplexporter/renderers/example_renderer.py b/mplexporter/renderers/example_renderer.py
index 474e197..3abde7a 100644
--- a/mplexporter/renderers/example_renderer.py
+++ b/mplexporter/renderers/example_renderer.py
@@ -10,13 +10,13 @@ class ExampleRenderer(Renderer):
     def __init__(self):
         self.output = ""
 
-    def open_figure(self, fig):
+    def open_figure(self, fig, properties):
         self.output += "opening figure\n"
 
     def close_figure(self, fig):
         self.output += "closing figure\n"
 
-    def open_axes(self, ax):
+    def open_axes(self, ax, properties):
         self.output += "  opening axes\n"
 
     def close_axes(self, ax):
diff --git a/mplexporter/renderers/vincent_renderer.py b/mplexporter/renderers/vincent_renderer.py
index dad53c1..657d3d4 100644
--- a/mplexporter/renderers/vincent_renderer.py
+++ b/mplexporter/renderers/vincent_renderer.py
@@ -4,10 +4,10 @@ from ..exporter import Exporter
 
 
 class VincentRenderer(Renderer):
-    def open_figure(self, fig):
+    def open_figure(self, fig, properties):
         self.chart = None
-        self.figwidth = int(fig.get_figwidth() * fig.dpi)
-        self.figheight = int(fig.get_figheight() * fig.dpi)
+        self.figwidth = int(properties['figwidth'] * properties['dpi'])
+        self.figheight = int(properties['figheight'] * properties['dpi'])
 
     def draw_line(self, data, coordinates, style):
         import vincent  # only import if VincentRenderer is used

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