Revision: 6062 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6062&view=rev Author: mdboom Date: 2008-09-03 19:58:01 +0000 (Wed, 03 Sep 2008)
Log Message: ----------- Add donut demo (to demonstrate compound paths) Modified Paths: -------------- trunk/matplotlib/examples/tests/backend_driver.py Added Paths: ----------- trunk/matplotlib/examples/api/donut_demo.py Added: trunk/matplotlib/examples/api/donut_demo.py =================================================================== --- trunk/matplotlib/examples/api/donut_demo.py (rev 0) +++ trunk/matplotlib/examples/api/donut_demo.py 2008-09-03 19:58:01 UTC (rev 6062) @@ -0,0 +1,54 @@ +import numpy as np +import matplotlib.path as mpath +import matplotlib.patches as mpatches +import matplotlib.pyplot as plt + +def wise(v): + if v == 1: + return "CCW" + else: + return "CW" + +def make_circle(r): + t = np.arange(0, np.pi * 2.0, 0.01) + t = t.reshape((len(t), 1)) + x = r * np.cos(t) + y = r * np.sin(t) + return np.hstack((x, y)) + +Path = mpath.Path + +fig = plt.figure() +ax = fig.add_subplot(111) + +inside_vertices = make_circle(0.5) +outside_vertices = make_circle(1.0) +codes = np.ones(len(inside_vertices), dtype=mpath.Path.code_type) * mpath.Path.LINETO +codes[0] = mpath.Path.MOVETO + +for i, (inside, outside) in enumerate(((1, 1), (1, -1), (-1, 1), (-1, -1))): + # Concatenate the inside and outside subpaths together, changing their + # order as needed + vertices = np.concatenate((outside_vertices[::outside], + inside_vertices[::inside])) + # Shift the path + vertices[:, 0] += i * 2.5 + # The codes will be all "LINETO" commands, except for "MOVETO"s at the + # beginning of each subpath + all_codes = np.concatenate((codes, codes)) + # Create the Path object + path = mpath.Path(vertices, all_codes) + # Add plot it + patch = mpatches.PathPatch(path, facecolor='#885500', edgecolor='black') + ax.add_patch(patch) + + ax.annotate("Outside %s,\nInside %s" % (wise(outside), wise(inside)), + (i * 2.5, -1.5), va="top", ha="center") + +ax.set_xlim(-2,10) +ax.set_ylim(-3,2) +ax.set_title('Mmm, donuts!') +ax.set_aspect(1.0) +plt.show() + + Modified: trunk/matplotlib/examples/tests/backend_driver.py =================================================================== --- trunk/matplotlib/examples/tests/backend_driver.py 2008-09-03 19:15:22 UTC (rev 6061) +++ trunk/matplotlib/examples/tests/backend_driver.py 2008-09-03 19:58:01 UTC (rev 6062) @@ -126,6 +126,8 @@ api_files = [ 'colorbar_only.py', 'color_cycle.py', + 'donut_demo.py', + 'path_patch_demo.py' ] units_dir = os.path.join('..', 'units') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Matplotlib-checkins mailing list Matplotlib-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins