[Python-modules-commits] [python-mplexporter] 53/135: fix log scale issues

Wolfgang Borgert debacle at moszumanska.debian.org
Tue Sep 23 21:19:03 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 0889cac3b5a69baabaa6f175c98e732f5d8d73fd
Author: Jake Vanderplas <vanderplas at astro.washington.edu>
Date:   Tue Feb 25 15:10:50 2014 -0800

    fix log scale issues
---
 mplexporter/exporter.py | 25 ++-----------------------
 mplexporter/utils.py    | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 23 deletions(-)

diff --git a/mplexporter/exporter.py b/mplexporter/exporter.py
index 6fe0571..64018e9 100644
--- a/mplexporter/exporter.py
+++ b/mplexporter/exporter.py
@@ -97,34 +97,13 @@ class Exporter(object):
 
     def crawl_fig(self, fig):
         """Crawl the figure and process all axes"""
-        properties = {'figwidth': fig.get_figwidth(),
-                      'figheight': fig.get_figheight(),
-                      'dpi': fig.dpi}
-        with self.renderer.draw_figure(fig, properties):
+        with self.renderer.draw_figure(fig, utils.get_figure_properties(fig)):
             for ax in fig.axes:
                 self.crawl_ax(ax)
 
     def crawl_ax(self, ax):
         """Crawl the axes and process all elements within"""
-        properties = {'xlim': ax.get_xlim(),
-                      'ylim': ax.get_ylim(),
-                      'xlabel': ax.get_xlabel(),
-                      'ylabel': ax.get_ylabel(),
-                      'title': ax.get_title(),
-                      'axesbg': utils.color_to_hex(ax.patch.get_facecolor()),
-                      'axesbgalpha': ax.patch.get_alpha(),
-                      'bounds': ax.get_position().bounds,
-                      'xgrid': bool(ax.xaxis._gridOnMajor
-                                    and ax.xaxis.get_gridlines()),
-                      'xgridstyle': utils.get_grid_style(ax, 'x'),
-                      'ygridstyle': utils.get_grid_style(ax, 'y'),
-                      'ygrid': bool(ax.yaxis._gridOnMajor
-                                    and ax.yaxis.get_gridlines()),
-                      'dynamic': ax.get_navigate(),
-                      'axes': [utils.get_axis_properties(ax.xaxis),
-                               utils.get_axis_properties(ax.yaxis)]}
-
-        with self.renderer.draw_axes(ax, properties):
+        with self.renderer.draw_axes(ax, utils.get_axes_properties(ax)):
             for line in ax.lines:
                 self.draw_line(ax, line)
             for text in ax.texts:
diff --git a/mplexporter/utils.py b/mplexporter/utils.py
index 8fda335..ce38226 100644
--- a/mplexporter/utils.py
+++ b/mplexporter/utils.py
@@ -232,6 +232,54 @@ def get_grid_style(ax, grid_type='x'):
         return {}
 
 
+def get_figure_properties(fig):
+    return {'figwidth': fig.get_figwidth(),
+            'figheight': fig.get_figheight(),
+            'dpi': fig.dpi}
+
+
+def get_axes_properties(ax):
+    props = {'xlabel': ax.get_xlabel(),
+             'ylabel': ax.get_ylabel(),
+             'title': ax.get_title(),
+             'axesbg': color_to_hex(ax.patch.get_facecolor()),
+             'axesbgalpha': ax.patch.get_alpha(),
+             'bounds': ax.get_position().bounds,
+             'xgrid': bool(ax.xaxis._gridOnMajor
+                           and ax.xaxis.get_gridlines()),
+             'xgridstyle': get_grid_style(ax, 'x'),
+             'ygridstyle': get_grid_style(ax, 'y'),
+             'ygrid': bool(ax.yaxis._gridOnMajor
+                           and ax.yaxis.get_gridlines()),
+             'dynamic': ax.get_navigate(),
+             'axes': [get_axis_properties(ax.xaxis),
+                      get_axis_properties(ax.yaxis)]}
+
+    for axname in ['x', 'y']:
+        axis = getattr(ax, axname + 'axis')
+        domain = getattr(ax, 'get_{0}lim'.format(axname))()
+        lim = domain
+        if isinstance(axis.converter, matplotlib.dates.DateConverter):
+            scale = 'date'
+            domain = ["new Date{0}".format((d.year, d.month - 1, d.day,
+                                            d.hour, d.minute, d.second,
+                                            d.microsecond * 1E-3))
+                      for d in matplotlib.dates.num2date(domain)]
+        else:
+            scale = axis.get_scale()
+
+        if scale not in ['date', 'linear', 'log']:
+            raise ValueError("Unknown axis scale: "
+                             "{0}".format(axis[axname].get_scale()))
+
+        props[axname + 'scale'] = scale
+        props[axname + 'lim'] = lim
+        props[axname + 'domain'] = domain
+
+    return props
+    
+
+
 def image_to_base64(image):
     """
     Convert a matplotlib image to a base64 png representation

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