[Python-modules-commits] [python-mplexporter] 41/135: Subplot in PlotlyRenderer is more functional. Two utils functions added.
Wolfgang Borgert
debacle at moszumanska.debian.org
Tue Sep 23 21:19:02 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 8aec6715c1377b2f6e54022fd0e526768f312e59
Author: theengineear <andseier at gmail.com>
Date: Mon Feb 24 22:39:57 2014 -0800
Subplot in PlotlyRenderer is more functional. Two utils functions added.
Previously, PlotlyRenderer would count the number of subplots and simply
make a column of them, equally spaced. It now uses the axes bounds to
exactly copy axes placement. Note, test objects are only copied
currently as strings, so formatting still changes upon import into
Plotly.
Two simple functions are added to the plotly_utils.py file to extract x
and y domain information from the axes bounds: (x0, y0, width, height)
to [x0, x1], [y0, y1].
---
mplexporter/renderers/plotly/plotly_renderer.py | 36 +++++++++++--------------
mplexporter/renderers/plotly/plotly_utils.py | 9 +++++++
2 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/mplexporter/renderers/plotly/plotly_renderer.py b/mplexporter/renderers/plotly/plotly_renderer.py
index 6dfd149..ff1801c 100644
--- a/mplexporter/renderers/plotly/plotly_renderer.py
+++ b/mplexporter/renderers/plotly/plotly_renderer.py
@@ -26,7 +26,6 @@ class PlotlyRenderer(Renderer):
def close_figure(self, fig):
self.output += "closing figure\n"
- self.configure_subplots()
self.configure_primary_axes() # changes 'y1', 'xaxis1', etc. to 'y', 'xaxis', etc.
self.layout['showlegend'] = False
@@ -38,13 +37,16 @@ class PlotlyRenderer(Renderer):
'xaxis{}'.format(self.axis_ct): {
'range': properties['xlim'],
'title': properties['xlabel'],
- 'showgrid': properties['xgrid']
+ 'showgrid': properties['xgrid'],
+ 'domain': plotly_utils.get_x_domain(properties['bounds']),
+ 'anchor': 'y{}'.format(self.axis_ct)
},
'yaxis{}'.format(self.axis_ct): {
- 'domain': [0,1],
'range': properties['ylim'],
'title': properties['ylabel'],
'showgrid': properties['ygrid'],
+ 'domain': plotly_utils.get_y_domain(properties['bounds']),
+ 'anchor': 'x{}'.format(self.axis_ct)
}
}
for key, value in layout.items():
@@ -97,25 +99,17 @@ class PlotlyRenderer(Renderer):
else:
self.output += " received {} markers with 'figure' coordinates, skipping!".format(data.shape[0])
- def configure_subplots(self):
- num_plots = self.axis_ct
- if num_plots > 1:
- spacing = 0.3/num_plots # magic numbers! change this!
- plot_dim = (1 - spacing*(num_plots-1))/num_plots
- for subplot_num in range(0, num_plots):
- domain_end = 1 - (plot_dim + spacing)*subplot_num
- domain_start = domain_end - plot_dim
- if domain_start < 0:
- domain_start = 0
- self.layout['yaxis{}'.format(subplot_num + 1)]['domain'] = [domain_start, domain_end]
- self.layout['xaxis{}'.format(subplot_num + 1)]['anchor'] = 'y{}'.format(subplot_num + 1)
-
def configure_primary_axes(self):
- for trace in self.data:
- if trace['xaxis'] == 'x1':
- trace['xaxis'] = 'x'
- if trace['yaxis'] == 'y1':
- trace['yaxis'] = 'y'
+ try:
+ for axis_no in range(0, len(self.data)):
+ if self.data[axis_no]['xaxis'] == 'x1':
+ del self.data[axis_no]['xaxis']
+ if self.data[axis_no]['yaxis'] == 'y1':
+ del self.data[axis_no]['yaxis']
+ except KeyError:
+ pass
+ except IndexError:
+ pass
if 'xaxis1' in self.layout:
self.layout['xaxis'] = self.layout.pop('xaxis1')
if 'yaxis1' in self.layout:
diff --git a/mplexporter/renderers/plotly/plotly_utils.py b/mplexporter/renderers/plotly/plotly_utils.py
index 7028ffd..c526d0b 100644
--- a/mplexporter/renderers/plotly/plotly_utils.py
+++ b/mplexporter/renderers/plotly/plotly_utils.py
@@ -4,6 +4,7 @@ def convert_symbol(mpl_symbol):
else:
return 'dot' # default
+
def convert_dash(mpl_dash):
if mpl_dash in dash_map:
return dash_map[mpl_dash]
@@ -11,6 +12,14 @@ def convert_dash(mpl_dash):
return 'solid' # default
+def get_x_domain(bounds):
+ return [bounds[0], bounds[0] + bounds[2]]
+
+
+def get_y_domain(bounds):
+ return [bounds[1], bounds[1] + bounds[3]]
+
+
dash_map = {
'10,0': 'solid',
'6,6': 'dash',
--
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