[Python-modules-commits] [python-mplexporter] 12/135: Added test_plotly module to tests package to use with PlotlyRenderer.
Wolfgang Borgert
debacle at moszumanska.debian.org
Tue Sep 23 21:18:58 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 06d9ffe4334863e0c36908cd3f30f995725c0172
Author: theengineear <andseier at gmail.com>
Date: Tue Feb 18 18:44:52 2014 -0800
Added test_plotly module to tests package to use with PlotlyRenderer.
The test_plotly function includes a public username and api_key (feel
free to put your own in in the test_plotly.py file). It presently
defines a function, plot_sin, which will create a matplotlib figure,
instantiate a PlotlyRenderer, instantiate an Exporter with the
PlotlyRenderer, and use the Exporter's 'run' function.
The output is mimicked from the test_basic module. This is helpful to
understand the interplay between the Exporter and PlotlyRenderer
objects. A simple output assertion should not throw any exceptions.
A plot will show up in your browser if this function is called.
---
mplexporter/tests/test_plotly.py | 41 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/mplexporter/tests/test_plotly.py b/mplexporter/tests/test_plotly.py
new file mode 100644
index 0000000..128a695
--- /dev/null
+++ b/mplexporter/tests/test_plotly.py
@@ -0,0 +1,41 @@
+from .. exporter import Exporter
+from .. renderers.plotly import PlotlyRenderer
+
+import numpy as np
+import matplotlib.pyplot as plt
+username = 'IPython.Demo'
+api_key = '1fw3zw2o13'
+
+
+def plot_sin():
+ # setup matplotlib plot
+ x = np.arange(0,1.0,0.01)
+ y1 = np.sin(2*np.pi*x)
+ y2 = np.cos(4*np.pi*x)
+ plt.plot(x, y1, 'b--', label='sin')
+ plt.plot(x, y2, 'ro', label='cos')
+ plt.title("It's a Sign")
+ plt.xlabel('time')
+ plt.ylabel('amplitude')
+ plt.legend().set_visible(True)
+
+ # 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)
+
+ # check output from PlotlyRenderer against expected output
+ for line1, line2 in zip(renderer.output.strip().split(),
+ PLOT_SIN_OUTPUT.strip().split()):
+ assert line1 == line2
+
+
+PLOT_SIN_OUTPUT = """
+opening figure
+ opening axes
+ draw line with 100 points
+ draw 100 markers
+ closing axes
+closing figure
+"""
\ No newline at end of file
--
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