[Python-modules-commits] [python-mplexporter] 37/135: add axis properties to exporter

Wolfgang Borgert debacle at moszumanska.debian.org
Tue Sep 23 21:19:01 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 94fb4001c90f4b6c0a77beb34b7ad39a2b3fb10c
Author: Jake Vanderplas <vanderplas at astro.washington.edu>
Date:   Mon Feb 24 14:56:59 2014 -0800

    add axis properties to exporter
---
 mplexporter/exporter.py | 44 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/mplexporter/exporter.py b/mplexporter/exporter.py
index 1643569..ed65fe7 100644
--- a/mplexporter/exporter.py
+++ b/mplexporter/exporter.py
@@ -8,6 +8,8 @@ import io
 import base64
 from . import utils
 
+import matplotlib
+from matplotlib import ticker
 
 class Exporter(object):
     """Matplotlib Exporter
@@ -105,6 +107,43 @@ class Exporter(object):
             for ax in fig.axes:
                 self._crawl_ax(ax)
 
+    def _axis_props(self, axis):
+        props = {}
+        label1On = axis._major_tick_kw.get('label1On', True)
+
+        if isinstance(axis, matplotlib.axis.XAxis):
+            if label1On:
+                props['position'] = "bottom"
+            else:
+                props['position'] = "top"
+        elif isinstance(axis, matplotlib.axis.YAxis):
+            if label1On:
+                props['position'] = "left"
+            else:
+                props['position'] = "right"
+        else:
+            raise ValueError("{0} should be an Axis instance".format(axis))
+
+        props['nticks'] = len(axis.get_major_locator()())
+
+        # Use tick values if appropriate
+        locator = axis.get_major_locator()
+        if isinstance(locator, ticker.FixedLocator):
+            props['tickvalues'] = list(locator())
+        else:
+            props['tickvalues'] = None
+
+        # Find tick formats
+        formatter = axis.get_major_formatter()
+        if isinstance(formatter, ticker.NullFormatter):
+            props['tickformat'] = ""
+        elif not any(label.get_visible() for label in axis.get_ticklabels()):
+            props['tickformat'] = ""
+        else:
+            props['tickformat'] = None
+
+        return props
+
     def _crawl_ax(self, ax):
         properties = {'xlim': ax.get_xlim(),
                       'ylim': ax.get_ylim(),
@@ -116,7 +155,10 @@ class Exporter(object):
                                     and ax.xaxis.get_gridlines()),
                       'ygrid': bool(ax.yaxis._gridOnMajor
                                     and ax.yaxis.get_gridlines()),
-                      'dynamic': ax.get_navigate()}
+                      'dynamic': ax.get_navigate(),
+                      'axes': [self._axis_props(ax.xaxis),
+                               self._axis_props(ax.yaxis)],
+                  }
         with self.renderer.draw_axes(ax, properties):
             self._extract_lines(ax)
             self._extract_patches(ax)

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