[Python-modules-commits] [python-mplexporter] 19/135: Separated out Exporter(PlotlyRenderer).run(fig) from fig_to_plotly(fig).

Wolfgang Borgert debacle at moszumanska.debian.org
Tue Sep 23 21:18:59 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 89de9c7d9b00ff9247213e74264eaa621a308ce5
Author: theengineear <andseier at gmail.com>
Date:   Wed Feb 19 16:52:27 2014 -0800

    Separated out Exporter(PlotlyRenderer).run(fig) from fig_to_plotly(fig).
    
    Changed code in plotly_renderer to include a definition for a
    fig_to_plotly function which opens a web browser with plot data taken
    from matplotlib and sent to plotly.
    
    Also, the file in the examples directory was updated to take this change
    into account.
---
 examples/plotly_example.py                      |  8 ++------
 mplexporter/renderers/plotly/__init__.py        |  2 +-
 mplexporter/renderers/plotly/plotly_renderer.py | 16 ++++++++++++----
 3 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/examples/plotly_example.py b/examples/plotly_example.py
index cefbc2e..12fe1f3 100644
--- a/examples/plotly_example.py
+++ b/examples/plotly_example.py
@@ -1,6 +1,4 @@
-from mplexporter.exporter import Exporter
-from mplexporter.renderers.plotly import PlotlyRenderer
-
+from mplexporter.renderers.plotly import PlotlyRenderer, fig_to_plotly
 import numpy as np
 import matplotlib.pyplot as plt
 username = 'IPython.Demo'
@@ -21,9 +19,7 @@ def plot_sin():
 
     # export info from matplotlib fig and render with plotly!
     fig = plt.gcf()
-    renderer = PlotlyRenderer(username=username, api_key=api_key)
-    exporter = Exporter(renderer)
-    exporter.run(fig)
+    fig_to_plotly(fig, username, api_key)
 
 if __name__ == '__main__':
     plot_sin()
diff --git a/mplexporter/renderers/plotly/__init__.py b/mplexporter/renderers/plotly/__init__.py
index 5b6144b..342da70 100644
--- a/mplexporter/renderers/plotly/__init__.py
+++ b/mplexporter/renderers/plotly/__init__.py
@@ -1 +1 @@
-from .plotly_renderer import PlotlyRenderer
\ No newline at end of file
+from .plotly_renderer import PlotlyRenderer, fig_to_plotly
\ No newline at end of file
diff --git a/mplexporter/renderers/plotly/plotly_renderer.py b/mplexporter/renderers/plotly/plotly_renderer.py
index efbabbb..2282275 100644
--- a/mplexporter/renderers/plotly/plotly_renderer.py
+++ b/mplexporter/renderers/plotly/plotly_renderer.py
@@ -7,6 +7,7 @@ import plotly
 
 from . import plotly_utils
 from .. base import Renderer
+from ... exporter import Exporter
 
 
 class PlotlyRenderer(Renderer):
@@ -25,9 +26,6 @@ class PlotlyRenderer(Renderer):
 
     def close_figure(self, fig):
         self.output += "closing figure\n"
-        print self.output
-        py = plotly.plotly(self.username, self.api_key)
-        py.plot(self.data, layout=self.layout)  # make call to plotly!
 
     def open_axes(self, ax, properties):
         self.output += "  opening axes\n"
@@ -75,4 +73,14 @@ class PlotlyRenderer(Renderer):
         # need to incorporate style['edgecolor']
         data_dict['marker']['symbol'] = plotly_utils.convert_symbol(style['marker'])
         # not sure whether we need to incorporate style['markerpath']
-        self.data += data_dict,
\ No newline at end of file
+        self.data += data_dict,
+
+
+def fig_to_plotly(fig, username=None, api_key=None):
+    """Convert a matplotlib figure to plotly dictionary
+
+    """
+    renderer = PlotlyRenderer(username=username, api_key=api_key)
+    Exporter(renderer).run(fig)
+    py = plotly.plotly(renderer.username, renderer.api_key)
+    py.plot(renderer.data, layout=renderer.layout)

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