[Python-modules-commits] [python-mplexporter] 66/135: Workaround for annotation transforms and axis label size.
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 7e38d643f86aa06fa3d5f1114b33e92b6c4bda62
Author: theengineear <andseier at gmail.com>
Date: Thu Feb 27 23:04:12 2014 -0800
Workaround for annotation transforms and axis label size.
These are hacky workarounds:
- Transform for annotation gives the transformation necessary to get
annotation coordinates into display coordinates. However, the
transformation to put these coordinates into data coordinates is not
given. A solution might be to either pass the axes object upon calling
draw_text. The 'private' _current_ax object from the base renderer class
was used to transform annotations to data coordinates (what plotly
generally uses)
- Axis labels are children of xaxis and yaxis instances, which are
children of the current axes object. When the label is passed to the
renderer, it would be helpful to either get this specific text instance
or the size. I used the current axis to get at the xaxis/yaxis objects
and then filted their lists of children until i found the label that
matched the one mplexporter passes to the renderer. I don't know that
there is a way to get around having to sort through the children and
compare strings. This probably won't break down for 'normal' use, but a
pathological example could make it do weird things.
---
mplexporter/renderers/plotly/plotly_renderer.py | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/mplexporter/renderers/plotly/plotly_renderer.py b/mplexporter/renderers/plotly/plotly_renderer.py
index 26cf1d1..c82d33a 100644
--- a/mplexporter/renderers/plotly/plotly_renderer.py
+++ b/mplexporter/renderers/plotly/plotly_renderer.py
@@ -4,6 +4,7 @@ Plotly Renderer
This is a renderer class to be used with an exporter for rendering plots in Plotly!
"""
import plotly
+import matplotlib
from . import plotly_utils
from .. base import Renderer
@@ -58,6 +59,24 @@ class PlotlyRenderer(Renderer):
'anchor': 'x{}'.format(self.axis_ct)
}
}
+ if layout['xaxis{}'.format(self.axis_ct)]['title'] not in [None, 'None', 'none', '']:
+ children = ax.xaxis.get_children()
+ for child in children:
+ if isinstance(child, matplotlib.text.Text):
+ if child.get_text() == layout['xaxis{}'.format(self.axis_ct)]['title']:
+ titlefont = {
+ 'size': child.get_size()
+ }
+ layout['xaxis{}'.format(self.axis_ct)]['titlefont'] = titlefont
+ if layout['yaxis{}'.format(self.axis_ct)]['title'] not in [None, 'None', 'none', '']:
+ children = ax.yaxis.get_children()
+ for child in children:
+ if isinstance(child, matplotlib.text.Text):
+ if child.get_text() == layout['yaxis{}'.format(self.axis_ct)]['title']:
+ titlefont = {
+ 'size': child.get_size()
+ }
+ layout['yaxis{}'.format(self.axis_ct)]['titlefont'] = titlefont
for key, value in layout.items():
self.layout[key] = value
@@ -111,8 +130,6 @@ class PlotlyRenderer(Renderer):
def draw_text(self, **props):
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']},
@@ -128,7 +145,6 @@ class PlotlyRenderer(Renderer):
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