[Python-modules-commits] [python-mplexporter] 65/135: Added positioning for annotations.

Wolfgang Borgert debacle at moszumanska.debian.org
Tue Sep 23 21:19:04 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 7a718c58dd472406978331b5a30f3de78928f8d9
Author: theengineear <andseier at gmail.com>
Date:   Thu Feb 27 22:07:47 2014 -0800

    Added positioning for annotations.
    
    Currently this uses a 'private' attribute from the base renderer class
    to use _current_ax to get an inverse transform for annotation position.
---
 mplexporter/renderers/plotly/plotly_renderer.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/mplexporter/renderers/plotly/plotly_renderer.py b/mplexporter/renderers/plotly/plotly_renderer.py
index d0c76f0..26cf1d1 100644
--- a/mplexporter/renderers/plotly/plotly_renderer.py
+++ b/mplexporter/renderers/plotly/plotly_renderer.py
@@ -112,12 +112,22 @@ class PlotlyRenderer(Renderer):
         if 'annotations' not in self.layout:
             self.layout['annotations'] = []
         print 'new annotation: ', props['text']
+        print 'coordinates: ', props['coordinates']
         annotation = {
             'text': props['text'],
             'font': {'color': props['style']['color'], 'size': props['style']['fontsize']},
             'xref': 'x{}'.format(self.axis_ct),
-            'yref': 'y{}'.format(self.axis_ct)
+            'yref': 'y{}'.format(self.axis_ct),
+            'x': props['position'][0],
+            'y': props['position'][1],
+            'showarrow': False  # change this later?
         }
+        if props['coordinates'] == 'points':
+            data_pos = self._current_ax.transData.inverted().transform(props['position'])
+            annotation['x'], annotation['y'] = data_pos[0], data_pos[1]
+        if props['coordinates'] == 'figure':
+            data_pos = self._current_ax.transFigure.inverted().transform(props['position'])
+            annotation['x'], annotation['y'] = data_pos[0], data_pos[1]
         print 'adding annotation dict:\n', annotation
         self.layout['annotations'] += annotation,
         # position=position, coordinates=coordinates, style=style, mplobj=text)

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