[Python-modules-commits] [python-mplexporter] 05/135: add ExampleRenderer to renderers

Wolfgang Borgert debacle at moszumanska.debian.org
Tue Sep 23 21:18:57 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 8d68e21ee9c1fa34e6aa173ff10b33ec28cf9023
Author: Jake Vanderplas <vanderplas at astro.washington.edu>
Date:   Mon Feb 17 08:21:54 2014 -0800

    add ExampleRenderer to renderers
---
 VincentTest.ipynb                                  | 23 +++++++++---------
 mplexporter/renderers/__init__.py                  |  3 ++-
 .../renderers/example_renderer.py                  | 21 +----------------
 .../renderers/{_vincent.py => vincent_renderer.py} |  0
 mplexporter/tests/test_basic.py                    | 27 ++--------------------
 5 files changed, 17 insertions(+), 57 deletions(-)

diff --git a/VincentTest.ipynb b/VincentTest.ipynb
index 4a649d5..1d8c6e3 100644
--- a/VincentTest.ipynb
+++ b/VincentTest.ipynb
@@ -90,7 +90,7 @@
        "metadata": {},
        "output_type": "display_data",
        "text": [
-        "<IPython.core.display.HTML at 0x106214110>"
+        "<IPython.core.display.HTML at 0x106114110>"
        ]
       }
      ],
@@ -109,7 +109,7 @@
       "    Display a vincent object in IPython\n",
       "    without forcing it to 100% of the page width\n",
       "    \"\"\"\n",
-      "    # the following is adapted from Visualization._repr_html_\n",
+      "    # the following is adapted from vincent.Visualization._repr_html_\n",
       "    id = random.randint(0, 2 ** 16)\n",
       "    html = '<div id=\"vis%d\"></div>' % id\n",
       "    html += '<script>\\n'\n",
@@ -150,7 +150,7 @@
      "outputs": [
       {
        "html": [
-        "<div id=\"vis13979\"></div><script>\n",
+        "<div id=\"vis22164\"></div><script>\n",
         "\n",
         "( function() {\n",
         "  var _do_plot = function() {\n",
@@ -159,7 +159,7 @@
         "      return;\n",
         "    }\n",
         "    vg.parse.spec({\"axes\": [{\"scale\": \"x\", \"type\": \"x\"}, {\"scale\": \"y\", \"type\": \"y\"}], \"data\": [{\"name\": \"table\", \"values\": [{\"col\": \"y\", \"idx\": 0.0, \"val\": 0.0}, {\"col\": \"y\", \"idx\": 0.10101010101010101, \"val\": 0.10083842025810461}, {\"col\": \"y\", \"idx\": 0.20202020202020202, \"val\": 0.20064885652268541}, {\"col\": \"y\", \"idx\": 0.30303030303030304, \"val\": 0.2984138044476411}, {\"col\": \"y\", \"idx\": 0.40404040404040403, \"val\ [...]
-        "      chart({el: \"#vis13979\"}).update();\n",
+        "      chart({el: \"#vis22164\"}).update();\n",
         "    });\n",
         "  };\n",
         "  _do_plot();\n",
@@ -171,7 +171,7 @@
        "output_type": "pyout",
        "prompt_number": 6,
        "text": [
-        "<IPython.core.display.HTML at 0x105f61f10>"
+        "<IPython.core.display.HTML at 0x105ea28d0>"
        ]
       }
      ],
@@ -181,8 +181,9 @@
      "cell_type": "code",
      "collapsed": false,
      "input": [
-      "x = np.random.random(50)\n",
-      "y = np.random.random(50)\n",
+      "np.random.seed(0)\n",
+      "x = np.random.normal(size=50)\n",
+      "y = np.random.normal(size=50)\n",
       "\n",
       "fig, ax = plt.subplots()\n",
       "ax.plot(x, y, 'or')\n",
@@ -194,7 +195,7 @@
      "outputs": [
       {
        "html": [
-        "<div id=\"vis49955\"></div><script>\n",
+        "<div id=\"vis14560\"></div><script>\n",
         "\n",
         "( function() {\n",
         "  var _do_plot = function() {\n",
@@ -202,8 +203,8 @@
         "      $([IPython.events]).on(\"vega_loaded.vincent\", _do_plot);\n",
         "      return;\n",
         "    }\n",
-        "    vg.parse.spec({\"axes\": [{\"scale\": \"x\", \"type\": \"x\"}, {\"scale\": \"y\", \"type\": \"y\"}], \"data\": [{\"name\": \"table\", \"values\": [{\"col\": \"y\", \"idx\": 0.80353589888620203, \"val\": 0.80115708889368742}, {\"col\": \"y\", \"idx\": 0.31049233307855506, \"val\": 0.55949939420633477}, {\"col\": \"y\", \"idx\": 0.14474598815449047, \"val\": 0.6038448274580166}, {\"col\": \"y\", \"idx\": 0.268781448824022, \"val\": 0.93918421327231294}, {\"col\": \"y\", \"idx\ [...]
-        "      chart({el: \"#vis49955\"}).update();\n",
+        "    vg.parse.spec({\"axes\": [{\"scale\": \"x\", \"type\": \"x\"}, {\"scale\": \"y\", \"type\": \"y\"}], \"data\": [{\"name\": \"table\", \"values\": [{\"col\": \"y\", \"idx\": 1.764052345967664, \"val\": -0.89546656119367563}, {\"col\": \"y\", \"idx\": 0.40015720836722329, \"val\": 0.38690249785926201}, {\"col\": \"y\", \"idx\": 0.9787379841057392, \"val\": -0.51080513756887302}, {\"col\": \"y\", \"idx\": 2.2408931992014578, \"val\": -1.1806321841224121}, {\"col\": \"y\", \"idx [...]
+        "      chart({el: \"#vis14560\"}).update();\n",
         "    });\n",
         "  };\n",
         "  _do_plot();\n",
@@ -215,7 +216,7 @@
        "output_type": "pyout",
        "prompt_number": 7,
        "text": [
-        "<IPython.core.display.HTML at 0x10715e150>"
+        "<IPython.core.display.HTML at 0x107091f90>"
        ]
       }
      ],
diff --git a/mplexporter/renderers/__init__.py b/mplexporter/renderers/__init__.py
index 8dc28ec..4a1e7c7 100644
--- a/mplexporter/renderers/__init__.py
+++ b/mplexporter/renderers/__init__.py
@@ -1,2 +1,3 @@
 from .base import Renderer
-from ._vincent import VincentRenderer, fig_to_vincent
+from .vincent_renderer import VincentRenderer, fig_to_vincent
+from .example_renderer import ExampleRenderer
diff --git a/renderer_example.py b/mplexporter/renderers/example_renderer.py
similarity index 65%
rename from renderer_example.py
rename to mplexporter/renderers/example_renderer.py
index 7a390a0..474e197 100644
--- a/renderer_example.py
+++ b/mplexporter/renderers/example_renderer.py
@@ -3,10 +3,7 @@ Example Renderer
 ================
 This shows an example of a do-nothing renderer, along with how to use it.
 """
-import matplotlib.pyplot as plt
-
-from mplexporter.renderer import Renderer
-from mplexporter.exporter import Exporter
+from .base import Renderer
 
 
 class ExampleRenderer(Renderer):
@@ -30,19 +27,3 @@ class ExampleRenderer(Renderer):
 
     def draw_markers(self, data, coordinates, style):
         self.output += "    draw {0} markers\n".format(data.shape[0])
-
-
-def run_example():
-    fig, ax = plt.subplots()
-    ax.plot(range(20), '-b')
-    ax.plot(range(10), '.k')
-
-    renderer = ExampleRenderer()
-    exporter = Exporter(renderer)
-
-    exporter.run(fig)
-    print renderer.output
-
-
-if __name__ == '__main__':
-    run_example()
diff --git a/mplexporter/renderers/_vincent.py b/mplexporter/renderers/vincent_renderer.py
similarity index 100%
rename from mplexporter/renderers/_vincent.py
rename to mplexporter/renderers/vincent_renderer.py
diff --git a/mplexporter/tests/test_basic.py b/mplexporter/tests/test_basic.py
index cb51f19..dbc3247 100644
--- a/mplexporter/tests/test_basic.py
+++ b/mplexporter/tests/test_basic.py
@@ -1,5 +1,5 @@
 from ..exporter import Exporter
-from ..renderers import Renderer
+from ..renderers import ExampleRenderer
 
 import matplotlib
 matplotlib.use('Agg')
@@ -16,35 +16,12 @@ closing figure
 """
 
 
-class FakeRenderer(Renderer):
-    def __init__(self):
-        self.output = ""
-
-    def open_figure(self, fig):
-        self.output += "opening figure\n"
-
-    def close_figure(self, fig):
-        self.output += "closing figure\n"
-
-    def open_axes(self, ax):
-        self.output += "  opening axes\n"
-
-    def close_axes(self, ax):
-        self.output += "  closing axes\n"
-
-    def draw_line(self, data, coordinates, style):
-        self.output += "    draw line with {0} points\n".format(data.shape[0])
-
-    def draw_markers(self, data, coordinates, style):
-        self.output += "    draw {0} markers\n".format(data.shape[0])
-
-
 def test_fakerenderer():
     fig, ax = plt.subplots()
     ax.plot(range(20), '-k')
     ax.plot(range(10), '.k')
 
-    renderer = FakeRenderer()
+    renderer = ExampleRenderer()
     exporter = Exporter(renderer)
     exporter.run(fig)
 

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