Revision: 7787
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7787&view=rev
Author:   mdboom
Date:     2009-09-18 16:18:51 +0000 (Fri, 18 Sep 2009)

Log Message:
-----------
Add tests for the simplification/clipping infrastructure.

Modified Paths:
--------------
    trunk/matplotlib/examples/tests/backend_driver.py
    trunk/matplotlib/lib/matplotlib/__init__.py
    trunk/matplotlib/lib/matplotlib/testing/compare.py

Added Paths:
-----------
    trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_simplification/
    
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_simplification/clipping.png
    
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_simplification/clipping_diamond.png
    
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_simplification/overflow.png
    
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_simplification/simplify_curve.png
    trunk/matplotlib/lib/matplotlib/tests/test_simplification.py

Removed Paths:
-------------
    trunk/matplotlib/examples/pylab_examples/simplification_clipping_test.py

Deleted: 
trunk/matplotlib/examples/pylab_examples/simplification_clipping_test.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/simplification_clipping_test.py    
2009-09-18 15:42:37 UTC (rev 7786)
+++ trunk/matplotlib/examples/pylab_examples/simplification_clipping_test.py    
2009-09-18 16:18:51 UTC (rev 7787)
@@ -1,72 +0,0 @@
-from pylab import *
-import numpy as np
-from matplotlib import patches, path
-nan = np.nan
-Path = path.Path
-
-t = arange(0.0, 2.0, 0.01)
-s = sin(2*pi*t)
-plot(t, s, linewidth=1.0)
-
-ylim((-0.20, -0.28))
-
-title('Should see four lines extending from bottom to top')
-
-figure()
-
-x = np.array([1.0,2.0,3.0,2.0e5])
-y = np.arange(len(x))
-plot(x,y)
-xlim(xmin=2,xmax=6)
-title("Should be monotonically increasing")
-
-figure()
-
-x = np.array([0.0, 1.0, 0.0, -1.0, 0.0])
-y = np.array([1.0, 0.0, -1.0, 0.0, 1.0])
-plot(x, y)
-xlim(xmin=-0.6, xmax=0.6)
-ylim(ymin=-0.6, ymax=0.6)
-title("Diamond shape, with segments visible in all four corners")
-
-figure()
-
-np.random.seed(0)
-x = np.random.uniform(size=(5000,)) * 50
-
-rcParams['path.simplify'] = True
-p1 = plot(x,solid_joinstyle='round',linewidth=2.0)
-
-path = p1[0].get_path()
-transform = p1[0].get_transform()
-path = transform.transform_path(path)
-simplified = list(path.iter_segments(simplify=(800, 600)))
-
-title("Original length: %d, simplified length: %d" % (len(path.vertices), 
len(simplified)))
-
-figure()
-
-x = np.sin(np.linspace(0, np.pi * 2.0, 1000)) + 
np.random.uniform(size=(1000,)) * 0.01
-
-rcParams['path.simplify'] = True
-p1 = plot(x,solid_joinstyle='round',linewidth=2.0)
-
-path = p1[0].get_path()
-transform = p1[0].get_transform()
-path = transform.transform_path(path)
-simplified = list(path.iter_segments(simplify=(800, 600)))
-
-title("Original length: %d, simplified length: %d" % (len(path.vertices), 
len(simplified)))
-
-figure()
-pp1 = patches.PathPatch(
-    Path([(0, 0), (1, 0), (1, 1), (nan, 1), (0, 0), (2, 0), (2, 2), (0, 0)],
-         [Path.MOVETO, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CURVE3, 
Path.CURVE3, Path.CURVE3, Path.CLOSEPOLY]),
-    fc="none")
-
-gca().add_patch(pp1)
-gca().set_xlim((0, 2))
-gca().set_ylim((0, 2))
-title("Should be one line with two curves below it")
-
-show()

Modified: trunk/matplotlib/examples/tests/backend_driver.py
===================================================================
--- trunk/matplotlib/examples/tests/backend_driver.py   2009-09-18 15:42:37 UTC 
(rev 7786)
+++ trunk/matplotlib/examples/tests/backend_driver.py   2009-09-18 16:18:51 UTC 
(rev 7787)
@@ -181,7 +181,6 @@
     'shared_axis_across_figures.py',
     'shared_axis_demo.py',
     'simple_plot.py',
-    'simplification_clipping_test.py',
     'specgram_demo.py',
     'spine_placement_demo.py',
     'spy_demos.py',

Modified: trunk/matplotlib/lib/matplotlib/__init__.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/__init__.py 2009-09-18 15:42:37 UTC (rev 
7786)
+++ trunk/matplotlib/lib/matplotlib/__init__.py 2009-09-18 16:18:51 UTC (rev 
7787)
@@ -886,6 +886,7 @@
     'matplotlib.tests.test_dates',
     'matplotlib.tests.test_spines',
     'matplotlib.tests.test_image',
+    'matplotlib.tests.test_simplification',
     ]
 
 def test(verbosity=0):

Modified: trunk/matplotlib/lib/matplotlib/testing/compare.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/testing/compare.py  2009-09-18 15:42:37 UTC 
(rev 7786)
+++ trunk/matplotlib/lib/matplotlib/testing/compare.py  2009-09-18 16:18:51 UTC 
(rev 7787)
@@ -80,7 +80,7 @@
 
    # img1 = "./baseline/plot.png"
    # img2 = "./output/plot.png"
-   #            
+   #
    # compare_images( img1, img2, 0.001 ):
 
    = INPUT VARIABLES

Added: 
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_simplification/clipping.png
===================================================================
(Binary files differ)


Property changes on: 
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_simplification/clipping.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: 
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_simplification/clipping_diamond.png
===================================================================
(Binary files differ)


Property changes on: 
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_simplification/clipping_diamond.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: 
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_simplification/overflow.png
===================================================================
(Binary files differ)


Property changes on: 
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_simplification/overflow.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: 
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_simplification/simplify_curve.png
===================================================================
(Binary files differ)


Property changes on: 
trunk/matplotlib/lib/matplotlib/tests/baseline_images/test_simplification/simplify_curve.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/matplotlib/lib/matplotlib/tests/test_simplification.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/tests/test_simplification.py                
                (rev 0)
+++ trunk/matplotlib/lib/matplotlib/tests/test_simplification.py        
2009-09-18 16:18:51 UTC (rev 7787)
@@ -0,0 +1,111 @@
+import numpy as np
+import matplotlib
+from matplotlib.testing.decorators import image_comparison, knownfailureif
+import matplotlib.pyplot as plt
+from matplotlib import patches, path
+
+from pylab import *
+import numpy as np
+from matplotlib import patches, path
+nan = np.nan
+Path = path.Path
+
+# NOTE: All of these tests assume that path.simplify is set to True
+# (the default)
+
+...@image_comparison(baseline_images=['clipping'])
+def test_clipping():
+    t = np.arange(0.0, 2.0, 0.01)
+    s = np.sin(2*pi*t)
+
+    fig = plt.figure()
+    ax = fig.add_subplot(111)
+    ax.plot(t, s, linewidth=1.0)
+    ax.set_ylim((-0.20, -0.28))
+    ax.set_xticks([])
+    ax.set_yticks([])
+    fig.savefig('clipping')
+
+...@image_comparison(baseline_images=['overflow'])
+def test_overflow():
+    x = np.array([1.0,2.0,3.0,2.0e5])
+    y = np.arange(len(x))
+
+    fig = plt.figure()
+    ax = fig.add_subplot(111)
+    ax.plot(x,y)
+    ax.set_xlim(xmin=2,xmax=6)
+    ax.set_xticks([])
+    ax.set_yticks([])
+
+    fig.savefig('overflow')
+
+...@image_comparison(baseline_images=['clipping_diamond'])
+def test_diamond():
+    x = np.array([0.0, 1.0, 0.0, -1.0, 0.0])
+    y = np.array([1.0, 0.0, -1.0, 0.0, 1.0])
+
+    fig = plt.figure()
+    ax = fig.add_subplot(111)
+    ax.plot(x, y)
+    ax.set_xlim(xmin=-0.6, xmax=0.6)
+    ax.set_ylim(ymin=-0.6, ymax=0.6)
+    ax.set_xticks([])
+    ax.set_yticks([])
+
+    fig.savefig('clipping_diamond')
+
+def test_noise():
+    np.random.seed(0)
+    x = np.random.uniform(size=(5000,)) * 50
+
+    fig = plt.figure()
+    ax = fig.add_subplot(111)
+    p1 = ax.plot(x, solid_joinstyle='round', linewidth=2.0)
+    ax.set_xticks([])
+    ax.set_yticks([])
+
+    path = p1[0].get_path()
+    transform = p1[0].get_transform()
+    path = transform.transform_path(path)
+    simplified = list(path.iter_segments(simplify=(800, 600)))
+
+    assert len(simplified) == 2662
+
+def test_sine_plus_noise():
+    np.random.seed(0)
+    x = np.sin(np.linspace(0, np.pi * 2.0, 1000)) + 
np.random.uniform(size=(1000,)) * 0.01
+
+    fig = plt.figure()
+    ax = fig.add_subplot(111)
+    p1 = ax.plot(x, solid_joinstyle='round', linewidth=2.0)
+    ax.set_xticks([])
+    ax.set_yticks([])
+
+    path = p1[0].get_path()
+    transform = p1[0].get_transform()
+    path = transform.transform_path(path)
+    simplified = list(path.iter_segments(simplify=(800, 600)))
+
+    assert len(simplified) == 279
+
+...@image_comparison(baseline_images=['simplify_curve'])
+def test_simplify_curve():
+    pp1 = patches.PathPatch(
+        Path([(0, 0), (1, 0), (1, 1), (nan, 1), (0, 0), (2, 0), (2, 2), (0, 
0)],
+             [Path.MOVETO, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CURVE3, 
Path.CURVE3, Path.CURVE3, Path.CLOSEPOLY]),
+        fc="none")
+
+    fig = plt.figure()
+    ax = fig.add_subplot(111)
+    ax.add_patch(pp1)
+    ax.set_xticks([])
+    ax.set_yticks([])
+    ax.set_xlim((0, 2))
+    ax.set_ylim((0, 2))
+
+    fig.savefig('simplify_curve')
+
+if __name__=='__main__':
+    import nose
+    nose.runmodule(argv=['-s','--with-doctest'], exit=False)


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to