You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(115) |
Aug
(120) |
Sep
(137) |
Oct
(170) |
Nov
(461) |
Dec
(263) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(120) |
Feb
(74) |
Mar
(35) |
Apr
(74) |
May
(245) |
Jun
(356) |
Jul
(240) |
Aug
(115) |
Sep
(78) |
Oct
(225) |
Nov
(98) |
Dec
(271) |
2009 |
Jan
(132) |
Feb
(84) |
Mar
(74) |
Apr
(56) |
May
(90) |
Jun
(79) |
Jul
(83) |
Aug
(296) |
Sep
(214) |
Oct
(76) |
Nov
(82) |
Dec
(66) |
2010 |
Jan
(46) |
Feb
(58) |
Mar
(51) |
Apr
(77) |
May
(58) |
Jun
(126) |
Jul
(128) |
Aug
(64) |
Sep
(50) |
Oct
(44) |
Nov
(48) |
Dec
(54) |
2011 |
Jan
(68) |
Feb
(52) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2018 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
|
|
|
|
|
|
1
(4) |
2
|
3
(8) |
4
(16) |
5
(40) |
6
(16) |
7
(9) |
8
(15) |
9
(6) |
10
(4) |
11
(28) |
12
(6) |
13
(2) |
14
(7) |
15
(8) |
16
|
17
|
18
(9) |
19
(2) |
20
(7) |
21
(3) |
22
(6) |
23
(25) |
24
(16) |
25
(8) |
26
(7) |
27
(3) |
28
(1) |
29
(4) |
30
(21) |
31
(15) |
|
|
|
|
|
Revision: 7435 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7435&view=rev Author: leejjoon Date: 2009年08月08日 21:11:18 +0000 (2009年8月08日) Log Message: ----------- fix example demo_ribbon_box.py Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/demo_ribbon_box.py Modified: trunk/matplotlib/examples/pylab_examples/demo_ribbon_box.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/demo_ribbon_box.py 2009年08月08日 18:24:52 UTC (rev 7434) +++ trunk/matplotlib/examples/pylab_examples/demo_ribbon_box.py 2009年08月08日 21:11:18 UTC (rev 7435) @@ -64,13 +64,13 @@ ): BboxImage.__init__(self, bbox, - cmap = None, - norm = None, - interpolation=None, - origin=None, - filternorm=1, - filterrad=4.0, - resample = False, + cmap = cmap, + norm = norm, + interpolation=interpolation, + origin=origin, + filternorm=filternorm, + filterrad=filterrad, + resample = resample, **kwargs ) @@ -115,7 +115,7 @@ for year, h, bc in zip(years, heights, box_colors): bbox0 = Bbox.from_extents(year-0.4, 0., year+0.4, h) bbox = TransformedBbox(bbox0, ax.transData) - rb_patch = RibbonBoxImage(bbox, bc) + rb_patch = RibbonBoxImage(bbox, bc, interpolation="bicubic") ax.add_artist(rb_patch) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 7434 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7434&view=rev Author: efiring Date: 2009年08月08日 18:24:52 +0000 (2009年8月08日) Log Message: ----------- Merged revisions 7428-7433 via svnmerge from https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v0_99_maint ........ r7428 | jdh2358 | 2009年08月08日 02:21:29 -1000 (2009年8月08日) | 1 line clean up mplot3d examples: use pyplot noy pylab and numpy rather than list comps and python random module ........ r7429 | jdh2358 | 2009年08月08日 03:53:24 -1000 (2009年8月08日) | 1 line two new examples using a compund path for a histogram; one animated ........ r7430 | jdh2358 | 2009年08月08日 03:58:52 -1000 (2009年8月08日) | 1 line two new examples using a compund path for a histogram; one animated ........ r7431 | jdh2358 | 2009年08月08日 05:10:08 -1000 (2009年8月08日) | 1 line use a class helper method to make the compound path from polys ........ r7432 | jdh2358 | 2009年08月08日 05:16:57 -1000 (2009年8月08日) | 1 line simplify poly array in example ........ r7433 | efiring | 2009年08月08日 08:16:01 -1000 (2009年8月08日) | 2 lines Fix excessive line length in annotations.rst ........ Modified Paths: -------------- trunk/matplotlib/doc/users/annotations.rst trunk/matplotlib/examples/mplot3d/2dcollections3d_demo.py trunk/matplotlib/examples/mplot3d/bars3d_demo.py trunk/matplotlib/examples/mplot3d/contour3d_demo.py trunk/matplotlib/examples/mplot3d/contour3d_demo2.py trunk/matplotlib/examples/mplot3d/contourf3d_demo.py trunk/matplotlib/examples/mplot3d/hist3d_demo.py trunk/matplotlib/examples/mplot3d/lines3d_demo.py trunk/matplotlib/examples/mplot3d/polys3d_demo.py trunk/matplotlib/examples/mplot3d/scatter3d_demo.py trunk/matplotlib/examples/mplot3d/surface3d_demo.py trunk/matplotlib/examples/mplot3d/surface3d_demo2.py trunk/matplotlib/examples/mplot3d/text3d_demo.py trunk/matplotlib/examples/mplot3d/wire3d_demo.py trunk/matplotlib/lib/matplotlib/path.py Added Paths: ----------- trunk/matplotlib/examples/animation/histogram_tkagg.py trunk/matplotlib/examples/api/histogram_path_demo.py Property Changed: ---------------- trunk/matplotlib/ trunk/matplotlib/doc/pyplots/README trunk/matplotlib/doc/sphinxext/gen_gallery.py trunk/matplotlib/doc/sphinxext/gen_rst.py trunk/matplotlib/examples/misc/multiprocess.py trunk/matplotlib/examples/mplot3d/contour3d_demo.py trunk/matplotlib/examples/mplot3d/contourf3d_demo.py trunk/matplotlib/examples/mplot3d/polys3d_demo.py trunk/matplotlib/examples/mplot3d/scatter3d_demo.py trunk/matplotlib/examples/mplot3d/surface3d_demo.py trunk/matplotlib/examples/mplot3d/wire3d_demo.py trunk/matplotlib/lib/matplotlib/sphinxext/mathmpl.py trunk/matplotlib/lib/matplotlib/sphinxext/only_directives.py trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py Property changes on: trunk/matplotlib ___________________________________________________________________ Modified: svnmerge-integrated - /branches/mathtex:1-7263 /branches/v0_98_5_maint:1-7253 /branches/v0_99_maint:1-7426 + /branches/mathtex:1-7263 /branches/v0_98_5_maint:1-7253 /branches/v0_99_maint:1-7433 Modified: svn:mergeinfo - /branches/v0_91_maint:5753-5771 /branches/v0_98_5_maint:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint:7338,7393,7395-7404,7407-7424 + /branches/v0_91_maint:5753-5771 /branches/v0_98_5_maint:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint:7338,7393,7395-7404,7407-7424,7428-7433 Property changes on: trunk/matplotlib/doc/pyplots/README ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_98_5_maint/doc/pyplots/README:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint/doc/pyplots/README:7338,7393,7395-7404,7407-7424 + /branches/v0_98_5_maint/doc/pyplots/README:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint/doc/pyplots/README:7338,7393,7395-7404,7407-7424,7428-7433 Property changes on: trunk/matplotlib/doc/sphinxext/gen_gallery.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/doc/_templates/gen_gallery.py:5753-5771 /branches/v0_98_5_maint/doc/sphinxext/gen_gallery.py:6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint/doc/sphinxext/gen_gallery.py:7338,7393,7395-7404,7407-7424 + /branches/v0_91_maint/doc/_templates/gen_gallery.py:5753-5771 /branches/v0_98_5_maint/doc/sphinxext/gen_gallery.py:6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint/doc/sphinxext/gen_gallery.py:7338,7393,7395-7404,7407-7424,7428-7433 Property changes on: trunk/matplotlib/doc/sphinxext/gen_rst.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/doc/examples/gen_rst.py:5753-5771 /branches/v0_98_5_maint/doc/sphinxext/gen_rst.py:6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint/doc/sphinxext/gen_rst.py:7338,7393,7395-7404,7407-7424 + /branches/v0_91_maint/doc/examples/gen_rst.py:5753-5771 /branches/v0_98_5_maint/doc/sphinxext/gen_rst.py:6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint/doc/sphinxext/gen_rst.py:7338,7393,7395-7404,7407-7424,7428-7433 Modified: trunk/matplotlib/doc/users/annotations.rst =================================================================== --- trunk/matplotlib/doc/users/annotations.rst 2009年08月08日 18:16:01 UTC (rev 7433) +++ trunk/matplotlib/doc/users/annotations.rst 2009年08月08日 18:24:52 UTC (rev 7434) @@ -56,17 +56,20 @@ properties in the optional keyword argument ``arrowprops``. -==================== =========================================================================== +==================== ===================================================== ``arrowprops`` key description -==================== =========================================================================== +==================== ===================================================== width the width of the arrow in points frac the fraction of the arrow length occupied by the head headwidth the width of the base of the arrow head in points -shrink move the tip and base some percent away from the annotated point and text -\*\*kwargs any key for :class:`matplotlib.patches.Polygon`, eg ``facecolor`` -==================== =========================================================================== +shrink move the tip and base some percent away from + the annotated point and text +\*\*kwargs any key for :class:`matplotlib.patches.Polygon`, + e.g. ``facecolor`` +==================== ===================================================== + In the example below, the ``xy`` point is in native coordinates (``xycoords`` defaults to 'data'). For a polar axes, this is in (theta, radius) space. The text in this example is placed in the @@ -78,4 +81,7 @@ .. plot:: pyplots/annotation_polar.py :include-source: -For more on all the wild and wonderful things you can do with annotations, including fancy arrows, see :ref:`plotting-guide-annotation` and :ref:`pylab_examples-annotation_demo`. +For more on all the wild and wonderful things you can do with +annotations, including fancy arrows, see :ref:`plotting-guide-annotation` +and :ref:`pylab_examples-annotation_demo`. + Copied: trunk/matplotlib/examples/animation/histogram_tkagg.py (from rev 7433, branches/v0_99_maint/examples/animation/histogram_tkagg.py) =================================================================== --- trunk/matplotlib/examples/animation/histogram_tkagg.py (rev 0) +++ trunk/matplotlib/examples/animation/histogram_tkagg.py 2009年08月08日 18:24:52 UTC (rev 7434) @@ -0,0 +1,70 @@ +""" +This example shows how to use a path patch to draw a bunch of +rectangles for an animated histogram +""" +import time +import numpy as np +import matplotlib +matplotlib.use('TkAgg') # do this before importing pylab + +import matplotlib.pyplot as plt +import matplotlib.patches as patches +import matplotlib.path as path + +fig = plt.figure() +ax = fig.add_subplot(111) + +# histogram our data with numpy +data = np.random.randn(1000) +n, bins = np.histogram(data, 100) + +# get the corners of the rectangles for the histogram +left = np.array(bins[:-1]) +right = np.array(bins[1:]) +bottom = np.zeros(len(left)) +top = bottom + n +nrects = len(left) + +# here comes the tricky part -- we have to set up the vertex and path +# codes arrays using moveto, lineto and closepoly + +# for each rect: 1 for the MOVETO, 3 for the LINETO, 1 for the +# CLOSEPOLY; the vert for the closepoly is ignored but we still need +# it to keep the codes aligned with the vertices +nverts = nrects*(1+3+1) +verts = np.zeros((nverts, 2)) +codes = np.ones(nverts, int) * path.Path.LINETO +codes[0::5] = path.Path.MOVETO +codes[4::5] = path.Path.CLOSEPOLY +verts[0::5,0] = left +verts[0::5,1] = bottom +verts[1::5,0] = left +verts[1::5,1] = top +verts[2::5,0] = right +verts[2::5,1] = top +verts[3::5,0] = right +verts[3::5,1] = bottom + +barpath = path.Path(verts, codes) +patch = patches.PathPatch(barpath, facecolor='green', edgecolor='yellow', alpha=0.5) +ax.add_patch(patch) + +ax.set_xlim(left[0], right[-1]) +ax.set_ylim(bottom.min(), top.max()) + +def animate(): + if animate.cnt>=100: + return + + animate.cnt += 1 + # simulate new data coming in + data = np.random.randn(1000) + n, bins = np.histogram(data, 100) + top = bottom + n + verts[1::5,1] = top + verts[2::5,1] = top + fig.canvas.draw() + fig.canvas.manager.window.after(100, animate) +animate.cnt = 0 +fig.canvas.manager.window.after(100, animate) +plt.show() Copied: trunk/matplotlib/examples/api/histogram_path_demo.py (from rev 7433, branches/v0_99_maint/examples/api/histogram_path_demo.py) =================================================================== --- trunk/matplotlib/examples/api/histogram_path_demo.py (rev 0) +++ trunk/matplotlib/examples/api/histogram_path_demo.py 2009年08月08日 18:24:52 UTC (rev 7434) @@ -0,0 +1,47 @@ +""" +This example shows how to use a path patch to draw a bunch of +rectangles. The technique of using lots of Rectangle instances, or +the faster method of using PolyCollections, were implemented before we +had proper paths with moveto/lineto, closepoly etc in mpl. Now that +we have them, we can draw collections of regularly shaped objects with +homogeous properties more efficiently with a PathCollection. This +example makes a histogram -- its more work to set up the vertex arrays +at the outset, but it should be much faster for large numbers of +objects +""" + +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.patches as patches +import matplotlib.path as path + +fig = plt.figure() +ax = fig.add_subplot(111) + +# histogram our data with numpy +data = np.random.randn(1000) +n, bins = np.histogram(data, 50) + +# get the corners of the rectangles for the histogram +left = np.array(bins[:-1]) +right = np.array(bins[1:]) +bottom = np.zeros(len(left)) +top = bottom + n + + +# we need a (numrects x numsides x 2) numpy array for the path helper +# function to build a compound path +XY = np.array([[left,left,right,right], [bottom,top,top,bottom]]).T + +# get the Path object +barpath = path.Path.make_compound_path_from_polys(XY) + +# make a patch out of it +patch = patches.PathPatch(barpath, facecolor='blue', edgecolor='gray', alpha=0.8) +ax.add_patch(patch) + +# update the view limits +ax.set_xlim(left[0], right[-1]) +ax.set_ylim(bottom.min(), top.max()) + +plt.show() Property changes on: trunk/matplotlib/examples/misc/multiprocess.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/examples/misc/log.py:5753-5771 /branches/v0_98_5_maint/examples/misc/log.py:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 /branches/v0_99_maint/examples/misc/multiprocess.py:7338,7393,7395-7404,7407-7424 + /branches/v0_91_maint/examples/misc/log.py:5753-5771 /branches/v0_98_5_maint/examples/misc/log.py:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 /branches/v0_99_maint/examples/misc/multiprocess.py:7338,7393,7395-7404,7407-7424,7428-7433 Modified: trunk/matplotlib/examples/mplot3d/2dcollections3d_demo.py =================================================================== --- trunk/matplotlib/examples/mplot3d/2dcollections3d_demo.py 2009年08月08日 18:16:01 UTC (rev 7433) +++ trunk/matplotlib/examples/mplot3d/2dcollections3d_demo.py 2009年08月08日 18:24:52 UTC (rev 7434) @@ -1,8 +1,8 @@ from mpl_toolkits.mplot3d import Axes3D import numpy as np -import pylab +import matplotlib.pyplot as plt -fig = pylab.figure() +fig = plt.figure() ax = Axes3D(fig) x = np.linspace(0, 1, 100) @@ -20,5 +20,5 @@ ax.set_ylim3d(0, 1) ax.set_zlim3d(0, 1) -pylab.show() +plt.show() Modified: trunk/matplotlib/examples/mplot3d/bars3d_demo.py =================================================================== --- trunk/matplotlib/examples/mplot3d/bars3d_demo.py 2009年08月08日 18:16:01 UTC (rev 7433) +++ trunk/matplotlib/examples/mplot3d/bars3d_demo.py 2009年08月08日 18:24:52 UTC (rev 7434) @@ -1,20 +1,17 @@ from mpl_toolkits.mplot3d import Axes3D -from matplotlib.collections import PolyCollection -from matplotlib.colors import colorConverter -import pylab -import random +import matplotlib.pyplot as plt import numpy as np -fig = pylab.figure() +fig = plt.figure() ax = Axes3D(fig) for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]): xs = np.arange(20) - ys = [random.random() for x in xs] + ys = np.random.rand(20) ax.bar(xs, ys, zs=z, zdir='y', color=c, alpha=0.8) ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') -pylab.show() +plt.show() Modified: trunk/matplotlib/examples/mplot3d/contour3d_demo.py =================================================================== --- trunk/matplotlib/examples/mplot3d/contour3d_demo.py 2009年08月08日 18:16:01 UTC (rev 7433) +++ trunk/matplotlib/examples/mplot3d/contour3d_demo.py 2009年08月08日 18:24:52 UTC (rev 7434) @@ -1,12 +1,11 @@ from mpl_toolkits.mplot3d import axes3d -import pylab -import random +import matplotlib.pyplot as plt -fig = pylab.figure() +fig = plt.figure() ax = axes3d.Axes3D(fig) X, Y, Z = axes3d.get_test_data(0.05) cset = ax.contour(X, Y, Z) ax.clabel(cset, fontsize=9, inline=1) -pylab.show() +plt.show() Property changes on: trunk/matplotlib/examples/mplot3d/contour3d_demo.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/examples/mplot3d/contour.py:5753-5771 /branches/v0_98_5_maint/examples/mplot3d/contour.py:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 /branches/v0_99_maint/examples/mplot3d/contour3d_demo.py:7338,7393,7395-7404,7407-7424 + /branches/v0_91_maint/examples/mplot3d/contour.py:5753-5771 /branches/v0_98_5_maint/examples/mplot3d/contour.py:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 /branches/v0_99_maint/examples/mplot3d/contour3d_demo.py:7338,7393,7395-7404,7407-7424,7428-7433 Modified: trunk/matplotlib/examples/mplot3d/contour3d_demo2.py =================================================================== --- trunk/matplotlib/examples/mplot3d/contour3d_demo2.py 2009年08月08日 18:16:01 UTC (rev 7433) +++ trunk/matplotlib/examples/mplot3d/contour3d_demo2.py 2009年08月08日 18:24:52 UTC (rev 7434) @@ -1,12 +1,11 @@ from mpl_toolkits.mplot3d import axes3d -import pylab -import random +import matplotlib.pyplot as plt -fig = pylab.figure() +fig = plt.figure() ax = axes3d.Axes3D(fig) X, Y, Z = axes3d.get_test_data(0.05) cset = ax.contour(X, Y, Z, 16, extend3d=True) ax.clabel(cset, fontsize=9, inline=1) -pylab.show() +plt.show() Modified: trunk/matplotlib/examples/mplot3d/contourf3d_demo.py =================================================================== --- trunk/matplotlib/examples/mplot3d/contourf3d_demo.py 2009年08月08日 18:16:01 UTC (rev 7433) +++ trunk/matplotlib/examples/mplot3d/contourf3d_demo.py 2009年08月08日 18:24:52 UTC (rev 7434) @@ -1,12 +1,11 @@ from mpl_toolkits.mplot3d import axes3d -import pylab -import random +import matplotlib.pyplot as plt -fig = pylab.figure() +fig = plt.figure() ax = axes3d.Axes3D(fig) X, Y, Z = axes3d.get_test_data(0.05) cset = ax.contourf(X, Y, Z) ax.clabel(cset, fontsize=9, inline=1) -pylab.show() +plt.show() Property changes on: trunk/matplotlib/examples/mplot3d/contourf3d_demo.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/examples/mplot3d/contourf.py:5753-5771 /branches/v0_98_5_maint/examples/mplot3d/contourf.py:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 /branches/v0_99_maint/examples/mplot3d/contourf3d_demo.py:7338,7393,7395-7404,7407-7424 + /branches/v0_91_maint/examples/mplot3d/contourf.py:5753-5771 /branches/v0_98_5_maint/examples/mplot3d/contourf.py:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 /branches/v0_99_maint/examples/mplot3d/contourf3d_demo.py:7338,7393,7395-7404,7407-7424,7428-7433 Modified: trunk/matplotlib/examples/mplot3d/hist3d_demo.py =================================================================== --- trunk/matplotlib/examples/mplot3d/hist3d_demo.py 2009年08月08日 18:16:01 UTC (rev 7433) +++ trunk/matplotlib/examples/mplot3d/hist3d_demo.py 2009年08月08日 18:24:52 UTC (rev 7434) @@ -1,27 +1,22 @@ from mpl_toolkits.mplot3d import Axes3D -from matplotlib.collections import PolyCollection -from matplotlib.colors import colorConverter -import pylab -import random +import matplotlib.pyplot as plt import numpy as np -fig = pylab.figure() +fig = plt.figure() ax = Axes3D(fig) -x = np.random.rand(100) * 4 -y = np.random.rand(100) * 4 +x, y = np.random.rand(2, 100) * 4 hist, xedges, yedges = np.histogram2d(x, y, bins=4) elements = (len(xedges) - 1) * (len(yedges) - 1) -xpos, ypos = np.meshgrid( - [xedges[i] + 0.25 for i in range(len(xedges) - 1)], - [yedges[i] + 0.25 for i in range(len(yedges) - 1)]) +xpos, ypos = np.meshgrid(xedges[:-1]+0.25, yedges[:-1]+0.25) + xpos = xpos.flatten() ypos = ypos.flatten() -zpos = [0] * elements -dx = [0.5] * elements -dy = [0.5] * elements +zpos = np.zeros(elements) +dx = 0.5 * np.ones_like(zpos) +dy = dx.copy() dz = hist.flatten() ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color='b') -pylab.show() +plt.show() Modified: trunk/matplotlib/examples/mplot3d/lines3d_demo.py =================================================================== --- trunk/matplotlib/examples/mplot3d/lines3d_demo.py 2009年08月08日 18:16:01 UTC (rev 7433) +++ trunk/matplotlib/examples/mplot3d/lines3d_demo.py 2009年08月08日 18:24:52 UTC (rev 7434) @@ -1,11 +1,11 @@ import matplotlib as mpl from mpl_toolkits.mplot3d import Axes3D import numpy as np -import pylab +import matplotlib.pyplot as plt mpl.rcParams['legend.fontsize'] = 10 -fig = pylab.figure() +fig = plt.figure() ax = Axes3D(fig) theta = np.linspace(-4 * np.pi, 4 * np.pi, 100) z = np.linspace(-2, 2, 100) @@ -15,5 +15,5 @@ ax.plot(x, y, z, label='parametric curve') ax.legend() -pylab.show() +plt.show() Modified: trunk/matplotlib/examples/mplot3d/polys3d_demo.py =================================================================== --- trunk/matplotlib/examples/mplot3d/polys3d_demo.py 2009年08月08日 18:16:01 UTC (rev 7433) +++ trunk/matplotlib/examples/mplot3d/polys3d_demo.py 2009年08月08日 18:24:52 UTC (rev 7434) @@ -1,11 +1,10 @@ from mpl_toolkits.mplot3d import Axes3D from matplotlib.collections import PolyCollection from matplotlib.colors import colorConverter -import pylab -import random +import matplotlib.pyplot as plt import numpy as np -fig = pylab.figure() +fig = plt.figure() ax = Axes3D(fig) cc = lambda arg: colorConverter.to_rgba(arg, alpha=0.6) @@ -14,7 +13,7 @@ verts = [] zs = [0.0, 1.0, 2.0, 3.0] for z in zs: - ys = [random.random() for x in xs] + ys = np.random.rand(len(xs)) ys[0], ys[-1] = 0, 0 verts.append(zip(xs, ys)) @@ -27,5 +26,5 @@ ax.set_ylim3d(-1, 4) ax.set_zlim3d(0, 1) -pylab.show() +plt.show() Property changes on: trunk/matplotlib/examples/mplot3d/polys3d_demo.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/examples/mplot3d/polys.py:5753-5771 /branches/v0_98_5_maint/examples/mplot3d/polys.py:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 /branches/v0_99_maint/examples/mplot3d/polys3d_demo.py:7338,7393,7395-7404,7407-7424 + /branches/v0_91_maint/examples/mplot3d/polys.py:5753-5771 /branches/v0_98_5_maint/examples/mplot3d/polys.py:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 /branches/v0_99_maint/examples/mplot3d/polys3d_demo.py:7338,7393,7395-7404,7407-7424,7428-7433 Modified: trunk/matplotlib/examples/mplot3d/scatter3d_demo.py =================================================================== --- trunk/matplotlib/examples/mplot3d/scatter3d_demo.py 2009年08月08日 18:16:01 UTC (rev 7433) +++ trunk/matplotlib/examples/mplot3d/scatter3d_demo.py 2009年08月08日 18:24:52 UTC (rev 7434) @@ -1,21 +1,23 @@ +import numpy as np from mpl_toolkits.mplot3d import Axes3D -import pylab -import random +import matplotlib.pyplot as plt -fig = pylab.figure() + +def randrange(n, vmin, vmax): + return (vmax-vmin)*np.random.rand(n) + vmin + +fig = plt.figure() ax = Axes3D(fig) n = 100 for c, zl, zh in [('r', -50, -25), ('b', -30, -5)]: - xs, ys, zs = zip(* - [(random.randrange(23, 32), - random.randrange(100), - random.randrange(zl, zh) - ) for i in range(n)]) + xs = randrange(n, 23, 32) + ys = randrange(n, 0, 100) + zs = randrange(n, zl, zh) ax.scatter(xs, ys, zs, c=c) ax.set_xlabel('X Label') ax.set_ylabel('Y Label') ax.set_zlabel('Z Label') -pylab.show() +plt.show() Property changes on: trunk/matplotlib/examples/mplot3d/scatter3d_demo.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/examples/mplot3d/scatter.py:5753-5771 /branches/v0_98_5_maint/examples/mplot3d/scatter.py:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 /branches/v0_99_maint/examples/mplot3d/scatter3d_demo.py:7338,7393,7395-7404,7407-7424 + /branches/v0_91_maint/examples/mplot3d/scatter.py:5753-5771 /branches/v0_98_5_maint/examples/mplot3d/scatter.py:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 /branches/v0_99_maint/examples/mplot3d/scatter3d_demo.py:7338,7393,7395-7404,7407-7424,7428-7433 Modified: trunk/matplotlib/examples/mplot3d/surface3d_demo.py =================================================================== --- trunk/matplotlib/examples/mplot3d/surface3d_demo.py 2009年08月08日 18:16:01 UTC (rev 7433) +++ trunk/matplotlib/examples/mplot3d/surface3d_demo.py 2009年08月08日 18:24:52 UTC (rev 7434) @@ -1,10 +1,9 @@ from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm -import pylab -import random +import matplotlib.pyplot as plt import numpy as np -fig = pylab.figure() +fig = plt.figure() ax = Axes3D(fig) X = np.arange(-5, 5, 0.25) Y = np.arange(-5, 5, 0.25) @@ -13,5 +12,5 @@ Z = np.sin(R) ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet) -pylab.show() +plt.show() Property changes on: trunk/matplotlib/examples/mplot3d/surface3d_demo.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/examples/mplot3d/surface.py:5753-5771 /branches/v0_98_5_maint/examples/mplot3d/surface.py:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 /branches/v0_99_maint/examples/mplot3d/surface3d_demo.py:7338,7393,7395-7404,7407-7424 + /branches/v0_91_maint/examples/mplot3d/surface.py:5753-5771 /branches/v0_98_5_maint/examples/mplot3d/surface.py:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 /branches/v0_99_maint/examples/mplot3d/surface3d_demo.py:7338,7393,7395-7404,7407-7424,7428-7433 Modified: trunk/matplotlib/examples/mplot3d/surface3d_demo2.py =================================================================== --- trunk/matplotlib/examples/mplot3d/surface3d_demo2.py 2009年08月08日 18:16:01 UTC (rev 7433) +++ trunk/matplotlib/examples/mplot3d/surface3d_demo2.py 2009年08月08日 18:24:52 UTC (rev 7434) @@ -1,9 +1,8 @@ from mpl_toolkits.mplot3d import Axes3D -import pylab -import random +import matplotlib.pyplot as plt import numpy as np -fig = pylab.figure() +fig = plt.figure() ax = Axes3D(fig) u = np.linspace(0, 2 * np.pi, 100) @@ -14,5 +13,5 @@ z = 10 * np.outer(np.ones(np.size(u)), np.cos(v)) ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b') -pylab.show() +plt.show() Modified: trunk/matplotlib/examples/mplot3d/text3d_demo.py =================================================================== --- trunk/matplotlib/examples/mplot3d/text3d_demo.py 2009年08月08日 18:16:01 UTC (rev 7433) +++ trunk/matplotlib/examples/mplot3d/text3d_demo.py 2009年08月08日 18:24:52 UTC (rev 7434) @@ -1,8 +1,7 @@ from mpl_toolkits.mplot3d import Axes3D -import pylab -import random +import matplotlib.pyplot as plt -fig = pylab.figure() +fig = plt.figure() ax = Axes3D(fig) zdirs = (None, 'x', 'y', 'z', (1, 1, 0), (1, 1, 1)) @@ -22,5 +21,5 @@ ax.set_ylabel('Y axis') ax.set_zlabel('Z axis') -pylab.show() +plt.show() Modified: trunk/matplotlib/examples/mplot3d/wire3d_demo.py =================================================================== --- trunk/matplotlib/examples/mplot3d/wire3d_demo.py 2009年08月08日 18:16:01 UTC (rev 7433) +++ trunk/matplotlib/examples/mplot3d/wire3d_demo.py 2009年08月08日 18:24:52 UTC (rev 7434) @@ -1,12 +1,11 @@ from mpl_toolkits.mplot3d import axes3d -import pylab -import random +import matplotlib.pyplot as plt import numpy as np -fig = pylab.figure() +fig = plt.figure() ax = axes3d.Axes3D(fig) X, Y, Z = axes3d.get_test_data(0.05) ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10) -pylab.show() +plt.show() Property changes on: trunk/matplotlib/examples/mplot3d/wire3d_demo.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/examples/mplot3d/wire.py:5753-5771 /branches/v0_98_5_maint/examples/mplot3d/wire.py:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 /branches/v0_99_maint/examples/mplot3d/wire3d_demo.py:7338,7393,7395-7404,7407-7424 + /branches/v0_91_maint/examples/mplot3d/wire.py:5753-5771 /branches/v0_98_5_maint/examples/mplot3d/wire.py:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080 /branches/v0_99_maint/examples/mplot3d/wire3d_demo.py:7338,7393,7395-7404,7407-7424,7428-7433 Modified: trunk/matplotlib/lib/matplotlib/path.py =================================================================== --- trunk/matplotlib/lib/matplotlib/path.py 2009年08月08日 18:16:01 UTC (rev 7433) +++ trunk/matplotlib/lib/matplotlib/path.py 2009年08月08日 18:24:52 UTC (rev 7434) @@ -129,6 +129,34 @@ self._interpolation_steps = _interpolation_steps @classmethod + def make_compound_path_from_polys(cls, XY): + """ + (static method) Make a compound path object to draw a number + of polygons with equal numbers of sides XY is a (numpolys x + numsides x 2) numpy array of vertices. Return object is a + :class:`Path` + + .. plot:: mpl_examples/api/histogram_path_demo.py + + """ + + # for each poly: 1 for the MOVETO, (numsides-1) for the LINETO, 1 for the + # CLOSEPOLY; the vert for the closepoly is ignored but we still need + # it to keep the codes aligned with the vertices + numpolys, numsides, two = XY.shape + assert(two==2) + stride = numsides + 1 + nverts = numpolys * stride + verts = np.zeros((nverts, 2)) + codes = np.ones(nverts, int) * cls.LINETO + codes[0::stride] = cls.MOVETO + codes[numsides::stride] = cls.CLOSEPOLY + for i in range(numsides): + verts[i::stride] = XY[:,i] + + return cls(verts, codes) + + @classmethod def make_compound_path(cls, *args): """ (staticmethod) Make a compound path from a list of Path Property changes on: trunk/matplotlib/lib/matplotlib/sphinxext/mathmpl.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/doc/sphinxext/mathmpl.py:5753-5771 /branches/v0_98_5_maint/lib/matplotlib/sphinxext/mathmpl.py:6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint/lib/matplotlib/sphinxext/mathmpl.py:7338,7393,7395-7404,7407-7424 + /branches/v0_91_maint/doc/sphinxext/mathmpl.py:5753-5771 /branches/v0_98_5_maint/lib/matplotlib/sphinxext/mathmpl.py:6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint/lib/matplotlib/sphinxext/mathmpl.py:7338,7393,7395-7404,7407-7424,7428-7433 Property changes on: trunk/matplotlib/lib/matplotlib/sphinxext/only_directives.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/doc/sphinxext/only_directives.py:5753-5771 /branches/v0_98_5_maint/lib/matplotlib/sphinxext/only_directives.py:6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint/lib/matplotlib/sphinxext/only_directives.py:7338,7393,7395-7404,7407-7424 + /branches/v0_91_maint/doc/sphinxext/only_directives.py:5753-5771 /branches/v0_98_5_maint/lib/matplotlib/sphinxext/only_directives.py:6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint/lib/matplotlib/sphinxext/only_directives.py:7338,7393,7395-7404,7407-7424,7428-7433 Property changes on: trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/doc/sphinxext/plot_directive.py:5753-5771 /branches/v0_98_5_maint/lib/matplotlib/sphinxext/plot_directive.py:6920-6925,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint/lib/matplotlib/sphinxext/plot_directive.py:7338,7393,7395-7404,7407-7424 + /branches/v0_91_maint/doc/sphinxext/plot_directive.py:5753-5771 /branches/v0_98_5_maint/lib/matplotlib/sphinxext/plot_directive.py:6920-6925,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint/lib/matplotlib/sphinxext/plot_directive.py:7338,7393,7395-7404,7407-7424,7428-7433 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 7433 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7433&view=rev Author: efiring Date: 2009年08月08日 18:16:01 +0000 (2009年8月08日) Log Message: ----------- Fix excessive line length in annotations.rst Modified Paths: -------------- branches/v0_99_maint/doc/users/annotations.rst Modified: branches/v0_99_maint/doc/users/annotations.rst =================================================================== --- branches/v0_99_maint/doc/users/annotations.rst 2009年08月08日 15:16:57 UTC (rev 7432) +++ branches/v0_99_maint/doc/users/annotations.rst 2009年08月08日 18:16:01 UTC (rev 7433) @@ -56,17 +56,20 @@ properties in the optional keyword argument ``arrowprops``. -==================== =========================================================================== +==================== ===================================================== ``arrowprops`` key description -==================== =========================================================================== +==================== ===================================================== width the width of the arrow in points frac the fraction of the arrow length occupied by the head headwidth the width of the base of the arrow head in points -shrink move the tip and base some percent away from the annotated point and text -\*\*kwargs any key for :class:`matplotlib.patches.Polygon`, eg ``facecolor`` -==================== =========================================================================== +shrink move the tip and base some percent away from + the annotated point and text +\*\*kwargs any key for :class:`matplotlib.patches.Polygon`, + e.g. ``facecolor`` +==================== ===================================================== + In the example below, the ``xy`` point is in native coordinates (``xycoords`` defaults to 'data'). For a polar axes, this is in (theta, radius) space. The text in this example is placed in the @@ -78,4 +81,7 @@ .. plot:: pyplots/annotation_polar.py :include-source: -For more on all the wild and wonderful things you can do with annotations, including fancy arrows, see :ref:`plotting-guide-annotation` and :ref:`pylab_examples-annotation_demo`. +For more on all the wild and wonderful things you can do with +annotations, including fancy arrows, see :ref:`plotting-guide-annotation` +and :ref:`pylab_examples-annotation_demo`. + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 7432 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7432&view=rev Author: jdh2358 Date: 2009年08月08日 15:16:57 +0000 (2009年8月08日) Log Message: ----------- simplify poly array in example Modified Paths: -------------- branches/v0_99_maint/examples/api/histogram_path_demo.py Modified: branches/v0_99_maint/examples/api/histogram_path_demo.py =================================================================== --- branches/v0_99_maint/examples/api/histogram_path_demo.py 2009年08月08日 15:10:08 UTC (rev 7431) +++ branches/v0_99_maint/examples/api/histogram_path_demo.py 2009年08月08日 15:16:57 UTC (rev 7432) @@ -22,34 +22,25 @@ data = np.random.randn(1000) n, bins = np.histogram(data, 50) - # get the corners of the rectangles for the histogram left = np.array(bins[:-1]) right = np.array(bins[1:]) bottom = np.zeros(len(left)) top = bottom + n -nrects = len(left) -XY = np.zeros((nrects, 4, 2)) -XY[:,0,0] = left -XY[:,0,1] = bottom -XY[:,1,0] = left -XY[:,1,1] = top +# we need a (numrects x numsides x 2) numpy array for the path helper +# function to build a compound path +XY = np.array([[left,left,right,right], [bottom,top,top,bottom]]).T -XY[:,2,0] = right -XY[:,2,1] = top - -XY[:,3,0] = right -XY[:,3,1] = bottom - - - +# get the Path object barpath = path.Path.make_compound_path_from_polys(XY) -print barpath.codes[:7], barpath.codes[-7:] + +# make a patch out of it patch = patches.PathPatch(barpath, facecolor='blue', edgecolor='gray', alpha=0.8) ax.add_patch(patch) +# update the view limits ax.set_xlim(left[0], right[-1]) ax.set_ylim(bottom.min(), top.max()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 7431 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7431&view=rev Author: jdh2358 Date: 2009年08月08日 15:10:08 +0000 (2009年8月08日) Log Message: ----------- use a class helper method to make the compound path from polys Modified Paths: -------------- branches/v0_99_maint/examples/animation/histogram_tkagg.py branches/v0_99_maint/examples/api/histogram_path_demo.py branches/v0_99_maint/lib/matplotlib/path.py Modified: branches/v0_99_maint/examples/animation/histogram_tkagg.py =================================================================== --- branches/v0_99_maint/examples/animation/histogram_tkagg.py 2009年08月08日 13:58:52 UTC (rev 7430) +++ branches/v0_99_maint/examples/animation/histogram_tkagg.py 2009年08月08日 15:10:08 UTC (rev 7431) @@ -2,6 +2,7 @@ This example shows how to use a path patch to draw a bunch of rectangles for an animated histogram """ +import time import numpy as np import matplotlib matplotlib.use('TkAgg') # do this before importing pylab @@ -52,6 +53,10 @@ ax.set_ylim(bottom.min(), top.max()) def animate(): + if animate.cnt>=100: + return + + animate.cnt += 1 # simulate new data coming in data = np.random.randn(1000) n, bins = np.histogram(data, 100) @@ -59,11 +64,7 @@ verts[1::5,1] = top verts[2::5,1] = top fig.canvas.draw() - -def run(): - for i in range(100): - fig.canvas.manager.window.after(100, animate) - - -fig.canvas.manager.window.after(100, run) + fig.canvas.manager.window.after(100, animate) +animate.cnt = 0 +fig.canvas.manager.window.after(100, animate) plt.show() Modified: branches/v0_99_maint/examples/api/histogram_path_demo.py =================================================================== --- branches/v0_99_maint/examples/api/histogram_path_demo.py 2009年08月08日 13:58:52 UTC (rev 7430) +++ branches/v0_99_maint/examples/api/histogram_path_demo.py 2009年08月08日 15:10:08 UTC (rev 7431) @@ -20,8 +20,9 @@ # histogram our data with numpy data = np.random.randn(1000) -n, bins = np.histogram(data, 100) +n, bins = np.histogram(data, 50) + # get the corners of the rectangles for the histogram left = np.array(bins[:-1]) right = np.array(bins[1:]) @@ -29,28 +30,24 @@ top = bottom + n nrects = len(left) -# here comes the tricky part -- we have to set up the vertex and path -# codes arrays using moveto, lineto and closepoly +XY = np.zeros((nrects, 4, 2)) +XY[:,0,0] = left +XY[:,0,1] = bottom -# for each rect: 1 for the MOVETO, 3 for the LINETO, 1 for the -# CLOSEPOLY; the vert for the closepoly is ignored but we still need -# it to keep the codes aligned with the vertices -nverts = nrects*(1+3+1) -verts = np.zeros((nverts, 2)) -codes = np.ones(nverts, int) * path.Path.LINETO -codes[0::5] = path.Path.MOVETO -codes[4::5] = path.Path.CLOSEPOLY -verts[0::5,0] = left -verts[0::5,1] = bottom -verts[1::5,0] = left -verts[1::5,1] = top -verts[2::5,0] = right -verts[2::5,1] = top -verts[3::5,0] = right -verts[3::5,1] = bottom +XY[:,1,0] = left +XY[:,1,1] = top -barpath = path.Path(verts, codes) -patch = patches.PathPatch(barpath, facecolor='green', edgecolor='yellow', alpha=0.5) +XY[:,2,0] = right +XY[:,2,1] = top + +XY[:,3,0] = right +XY[:,3,1] = bottom + + + +barpath = path.Path.make_compound_path_from_polys(XY) +print barpath.codes[:7], barpath.codes[-7:] +patch = patches.PathPatch(barpath, facecolor='blue', edgecolor='gray', alpha=0.8) ax.add_patch(patch) ax.set_xlim(left[0], right[-1]) Modified: branches/v0_99_maint/lib/matplotlib/path.py =================================================================== --- branches/v0_99_maint/lib/matplotlib/path.py 2009年08月08日 13:58:52 UTC (rev 7430) +++ branches/v0_99_maint/lib/matplotlib/path.py 2009年08月08日 15:10:08 UTC (rev 7431) @@ -129,6 +129,34 @@ self._interpolation_steps = _interpolation_steps @classmethod + def make_compound_path_from_polys(cls, XY): + """ + (static method) Make a compound path object to draw a number + of polygons with equal numbers of sides XY is a (numpolys x + numsides x 2) numpy array of vertices. Return object is a + :class:`Path` + + .. plot:: mpl_examples/api/histogram_path_demo.py + + """ + + # for each poly: 1 for the MOVETO, (numsides-1) for the LINETO, 1 for the + # CLOSEPOLY; the vert for the closepoly is ignored but we still need + # it to keep the codes aligned with the vertices + numpolys, numsides, two = XY.shape + assert(two==2) + stride = numsides + 1 + nverts = numpolys * stride + verts = np.zeros((nverts, 2)) + codes = np.ones(nverts, int) * cls.LINETO + codes[0::stride] = cls.MOVETO + codes[numsides::stride] = cls.CLOSEPOLY + for i in range(numsides): + verts[i::stride] = XY[:,i] + + return cls(verts, codes) + + @classmethod def make_compound_path(cls, *args): """ (staticmethod) Make a compound path from a list of Path This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 7430 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7430&view=rev Author: jdh2358 Date: 2009年08月08日 13:58:52 +0000 (2009年8月08日) Log Message: ----------- two new examples using a compund path for a histogram; one animated Modified Paths: -------------- branches/v0_99_maint/examples/animation/histogram_tkagg.py Modified: branches/v0_99_maint/examples/animation/histogram_tkagg.py =================================================================== --- branches/v0_99_maint/examples/animation/histogram_tkagg.py 2009年08月08日 13:53:24 UTC (rev 7429) +++ branches/v0_99_maint/examples/animation/histogram_tkagg.py 2009年08月08日 13:58:52 UTC (rev 7430) @@ -1,15 +1,7 @@ """ This example shows how to use a path patch to draw a bunch of -rectangles. The technique of using lots of Rectangle instances, or -the faster method of using PolyCollections, were implemented before we -had proper paths with moveto/lineto, closepoly etc in mpl. Now that -we have them, we can draw collections of regularly shaped objects with -homogeous properties more efficiently with a PathCollection. This -example makes a histogram -- its more work to set up the vertex arrays -at the outset, but it should be much faster for large numbers of -objects +rectangles for an animated histogram """ -import time import numpy as np import matplotlib matplotlib.use('TkAgg') # do this before importing pylab @@ -60,7 +52,6 @@ ax.set_ylim(bottom.min(), top.max()) def animate(): - tstart = time.time() # for profiling # simulate new data coming in data = np.random.randn(1000) n, bins = np.histogram(data, 100) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 7429 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7429&view=rev Author: jdh2358 Date: 2009年08月08日 13:53:24 +0000 (2009年8月08日) Log Message: ----------- two new examples using a compund path for a histogram; one animated Added Paths: ----------- branches/v0_99_maint/examples/animation/histogram_tkagg.py branches/v0_99_maint/examples/api/histogram_path_demo.py Added: branches/v0_99_maint/examples/animation/histogram_tkagg.py =================================================================== --- branches/v0_99_maint/examples/animation/histogram_tkagg.py (rev 0) +++ branches/v0_99_maint/examples/animation/histogram_tkagg.py 2009年08月08日 13:53:24 UTC (rev 7429) @@ -0,0 +1,78 @@ +""" +This example shows how to use a path patch to draw a bunch of +rectangles. The technique of using lots of Rectangle instances, or +the faster method of using PolyCollections, were implemented before we +had proper paths with moveto/lineto, closepoly etc in mpl. Now that +we have them, we can draw collections of regularly shaped objects with +homogeous properties more efficiently with a PathCollection. This +example makes a histogram -- its more work to set up the vertex arrays +at the outset, but it should be much faster for large numbers of +objects +""" +import time +import numpy as np +import matplotlib +matplotlib.use('TkAgg') # do this before importing pylab + +import matplotlib.pyplot as plt +import matplotlib.patches as patches +import matplotlib.path as path + +fig = plt.figure() +ax = fig.add_subplot(111) + +# histogram our data with numpy +data = np.random.randn(1000) +n, bins = np.histogram(data, 100) + +# get the corners of the rectangles for the histogram +left = np.array(bins[:-1]) +right = np.array(bins[1:]) +bottom = np.zeros(len(left)) +top = bottom + n +nrects = len(left) + +# here comes the tricky part -- we have to set up the vertex and path +# codes arrays using moveto, lineto and closepoly + +# for each rect: 1 for the MOVETO, 3 for the LINETO, 1 for the +# CLOSEPOLY; the vert for the closepoly is ignored but we still need +# it to keep the codes aligned with the vertices +nverts = nrects*(1+3+1) +verts = np.zeros((nverts, 2)) +codes = np.ones(nverts, int) * path.Path.LINETO +codes[0::5] = path.Path.MOVETO +codes[4::5] = path.Path.CLOSEPOLY +verts[0::5,0] = left +verts[0::5,1] = bottom +verts[1::5,0] = left +verts[1::5,1] = top +verts[2::5,0] = right +verts[2::5,1] = top +verts[3::5,0] = right +verts[3::5,1] = bottom + +barpath = path.Path(verts, codes) +patch = patches.PathPatch(barpath, facecolor='green', edgecolor='yellow', alpha=0.5) +ax.add_patch(patch) + +ax.set_xlim(left[0], right[-1]) +ax.set_ylim(bottom.min(), top.max()) + +def animate(): + tstart = time.time() # for profiling + # simulate new data coming in + data = np.random.randn(1000) + n, bins = np.histogram(data, 100) + top = bottom + n + verts[1::5,1] = top + verts[2::5,1] = top + fig.canvas.draw() + +def run(): + for i in range(100): + fig.canvas.manager.window.after(100, animate) + + +fig.canvas.manager.window.after(100, run) +plt.show() Added: branches/v0_99_maint/examples/api/histogram_path_demo.py =================================================================== --- branches/v0_99_maint/examples/api/histogram_path_demo.py (rev 0) +++ branches/v0_99_maint/examples/api/histogram_path_demo.py 2009年08月08日 13:53:24 UTC (rev 7429) @@ -0,0 +1,59 @@ +""" +This example shows how to use a path patch to draw a bunch of +rectangles. The technique of using lots of Rectangle instances, or +the faster method of using PolyCollections, were implemented before we +had proper paths with moveto/lineto, closepoly etc in mpl. Now that +we have them, we can draw collections of regularly shaped objects with +homogeous properties more efficiently with a PathCollection. This +example makes a histogram -- its more work to set up the vertex arrays +at the outset, but it should be much faster for large numbers of +objects +""" + +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.patches as patches +import matplotlib.path as path + +fig = plt.figure() +ax = fig.add_subplot(111) + +# histogram our data with numpy +data = np.random.randn(1000) +n, bins = np.histogram(data, 100) + +# get the corners of the rectangles for the histogram +left = np.array(bins[:-1]) +right = np.array(bins[1:]) +bottom = np.zeros(len(left)) +top = bottom + n +nrects = len(left) + +# here comes the tricky part -- we have to set up the vertex and path +# codes arrays using moveto, lineto and closepoly + +# for each rect: 1 for the MOVETO, 3 for the LINETO, 1 for the +# CLOSEPOLY; the vert for the closepoly is ignored but we still need +# it to keep the codes aligned with the vertices +nverts = nrects*(1+3+1) +verts = np.zeros((nverts, 2)) +codes = np.ones(nverts, int) * path.Path.LINETO +codes[0::5] = path.Path.MOVETO +codes[4::5] = path.Path.CLOSEPOLY +verts[0::5,0] = left +verts[0::5,1] = bottom +verts[1::5,0] = left +verts[1::5,1] = top +verts[2::5,0] = right +verts[2::5,1] = top +verts[3::5,0] = right +verts[3::5,1] = bottom + +barpath = path.Path(verts, codes) +patch = patches.PathPatch(barpath, facecolor='green', edgecolor='yellow', alpha=0.5) +ax.add_patch(patch) + +ax.set_xlim(left[0], right[-1]) +ax.set_ylim(bottom.min(), top.max()) + +plt.show() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 7428 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7428&view=rev Author: jdh2358 Date: 2009年08月08日 12:21:29 +0000 (2009年8月08日) Log Message: ----------- clean up mplot3d examples: use pyplot noy pylab and numpy rather than list comps and python random module Modified Paths: -------------- branches/v0_99_maint/examples/mplot3d/2dcollections3d_demo.py branches/v0_99_maint/examples/mplot3d/bars3d_demo.py branches/v0_99_maint/examples/mplot3d/contour3d_demo.py branches/v0_99_maint/examples/mplot3d/contour3d_demo2.py branches/v0_99_maint/examples/mplot3d/contourf3d_demo.py branches/v0_99_maint/examples/mplot3d/hist3d_demo.py branches/v0_99_maint/examples/mplot3d/lines3d_demo.py branches/v0_99_maint/examples/mplot3d/polys3d_demo.py branches/v0_99_maint/examples/mplot3d/scatter3d_demo.py branches/v0_99_maint/examples/mplot3d/surface3d_demo.py branches/v0_99_maint/examples/mplot3d/surface3d_demo2.py branches/v0_99_maint/examples/mplot3d/text3d_demo.py branches/v0_99_maint/examples/mplot3d/wire3d_demo.py Modified: branches/v0_99_maint/examples/mplot3d/2dcollections3d_demo.py =================================================================== --- branches/v0_99_maint/examples/mplot3d/2dcollections3d_demo.py 2009年08月08日 11:25:32 UTC (rev 7427) +++ branches/v0_99_maint/examples/mplot3d/2dcollections3d_demo.py 2009年08月08日 12:21:29 UTC (rev 7428) @@ -1,8 +1,8 @@ from mpl_toolkits.mplot3d import Axes3D import numpy as np -import pylab +import matplotlib.pyplot as plt -fig = pylab.figure() +fig = plt.figure() ax = Axes3D(fig) x = np.linspace(0, 1, 100) @@ -20,5 +20,5 @@ ax.set_ylim3d(0, 1) ax.set_zlim3d(0, 1) -pylab.show() +plt.show() Modified: branches/v0_99_maint/examples/mplot3d/bars3d_demo.py =================================================================== --- branches/v0_99_maint/examples/mplot3d/bars3d_demo.py 2009年08月08日 11:25:32 UTC (rev 7427) +++ branches/v0_99_maint/examples/mplot3d/bars3d_demo.py 2009年08月08日 12:21:29 UTC (rev 7428) @@ -1,20 +1,17 @@ from mpl_toolkits.mplot3d import Axes3D -from matplotlib.collections import PolyCollection -from matplotlib.colors import colorConverter -import pylab -import random +import matplotlib.pyplot as plt import numpy as np -fig = pylab.figure() +fig = plt.figure() ax = Axes3D(fig) for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]): xs = np.arange(20) - ys = [random.random() for x in xs] + ys = np.random.rand(20) ax.bar(xs, ys, zs=z, zdir='y', color=c, alpha=0.8) ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') -pylab.show() +plt.show() Modified: branches/v0_99_maint/examples/mplot3d/contour3d_demo.py =================================================================== --- branches/v0_99_maint/examples/mplot3d/contour3d_demo.py 2009年08月08日 11:25:32 UTC (rev 7427) +++ branches/v0_99_maint/examples/mplot3d/contour3d_demo.py 2009年08月08日 12:21:29 UTC (rev 7428) @@ -1,12 +1,11 @@ from mpl_toolkits.mplot3d import axes3d -import pylab -import random +import matplotlib.pyplot as plt -fig = pylab.figure() +fig = plt.figure() ax = axes3d.Axes3D(fig) X, Y, Z = axes3d.get_test_data(0.05) cset = ax.contour(X, Y, Z) ax.clabel(cset, fontsize=9, inline=1) -pylab.show() +plt.show() Modified: branches/v0_99_maint/examples/mplot3d/contour3d_demo2.py =================================================================== --- branches/v0_99_maint/examples/mplot3d/contour3d_demo2.py 2009年08月08日 11:25:32 UTC (rev 7427) +++ branches/v0_99_maint/examples/mplot3d/contour3d_demo2.py 2009年08月08日 12:21:29 UTC (rev 7428) @@ -1,12 +1,11 @@ from mpl_toolkits.mplot3d import axes3d -import pylab -import random +import matplotlib.pyplot as plt -fig = pylab.figure() +fig = plt.figure() ax = axes3d.Axes3D(fig) X, Y, Z = axes3d.get_test_data(0.05) cset = ax.contour(X, Y, Z, 16, extend3d=True) ax.clabel(cset, fontsize=9, inline=1) -pylab.show() +plt.show() Modified: branches/v0_99_maint/examples/mplot3d/contourf3d_demo.py =================================================================== --- branches/v0_99_maint/examples/mplot3d/contourf3d_demo.py 2009年08月08日 11:25:32 UTC (rev 7427) +++ branches/v0_99_maint/examples/mplot3d/contourf3d_demo.py 2009年08月08日 12:21:29 UTC (rev 7428) @@ -1,12 +1,11 @@ from mpl_toolkits.mplot3d import axes3d -import pylab -import random +import matplotlib.pyplot as plt -fig = pylab.figure() +fig = plt.figure() ax = axes3d.Axes3D(fig) X, Y, Z = axes3d.get_test_data(0.05) cset = ax.contourf(X, Y, Z) ax.clabel(cset, fontsize=9, inline=1) -pylab.show() +plt.show() Modified: branches/v0_99_maint/examples/mplot3d/hist3d_demo.py =================================================================== --- branches/v0_99_maint/examples/mplot3d/hist3d_demo.py 2009年08月08日 11:25:32 UTC (rev 7427) +++ branches/v0_99_maint/examples/mplot3d/hist3d_demo.py 2009年08月08日 12:21:29 UTC (rev 7428) @@ -1,27 +1,22 @@ from mpl_toolkits.mplot3d import Axes3D -from matplotlib.collections import PolyCollection -from matplotlib.colors import colorConverter -import pylab -import random +import matplotlib.pyplot as plt import numpy as np -fig = pylab.figure() +fig = plt.figure() ax = Axes3D(fig) -x = np.random.rand(100) * 4 -y = np.random.rand(100) * 4 +x, y = np.random.rand(2, 100) * 4 hist, xedges, yedges = np.histogram2d(x, y, bins=4) elements = (len(xedges) - 1) * (len(yedges) - 1) -xpos, ypos = np.meshgrid( - [xedges[i] + 0.25 for i in range(len(xedges) - 1)], - [yedges[i] + 0.25 for i in range(len(yedges) - 1)]) +xpos, ypos = np.meshgrid(xedges[:-1]+0.25, yedges[:-1]+0.25) + xpos = xpos.flatten() ypos = ypos.flatten() -zpos = [0] * elements -dx = [0.5] * elements -dy = [0.5] * elements +zpos = np.zeros(elements) +dx = 0.5 * np.ones_like(zpos) +dy = dx.copy() dz = hist.flatten() ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color='b') -pylab.show() +plt.show() Modified: branches/v0_99_maint/examples/mplot3d/lines3d_demo.py =================================================================== --- branches/v0_99_maint/examples/mplot3d/lines3d_demo.py 2009年08月08日 11:25:32 UTC (rev 7427) +++ branches/v0_99_maint/examples/mplot3d/lines3d_demo.py 2009年08月08日 12:21:29 UTC (rev 7428) @@ -1,11 +1,11 @@ import matplotlib as mpl from mpl_toolkits.mplot3d import Axes3D import numpy as np -import pylab +import matplotlib.pyplot as plt mpl.rcParams['legend.fontsize'] = 10 -fig = pylab.figure() +fig = plt.figure() ax = Axes3D(fig) theta = np.linspace(-4 * np.pi, 4 * np.pi, 100) z = np.linspace(-2, 2, 100) @@ -15,5 +15,5 @@ ax.plot(x, y, z, label='parametric curve') ax.legend() -pylab.show() +plt.show() Modified: branches/v0_99_maint/examples/mplot3d/polys3d_demo.py =================================================================== --- branches/v0_99_maint/examples/mplot3d/polys3d_demo.py 2009年08月08日 11:25:32 UTC (rev 7427) +++ branches/v0_99_maint/examples/mplot3d/polys3d_demo.py 2009年08月08日 12:21:29 UTC (rev 7428) @@ -1,11 +1,10 @@ from mpl_toolkits.mplot3d import Axes3D from matplotlib.collections import PolyCollection from matplotlib.colors import colorConverter -import pylab -import random +import matplotlib.pyplot as plt import numpy as np -fig = pylab.figure() +fig = plt.figure() ax = Axes3D(fig) cc = lambda arg: colorConverter.to_rgba(arg, alpha=0.6) @@ -14,7 +13,7 @@ verts = [] zs = [0.0, 1.0, 2.0, 3.0] for z in zs: - ys = [random.random() for x in xs] + ys = np.random.rand(len(xs)) ys[0], ys[-1] = 0, 0 verts.append(zip(xs, ys)) @@ -27,5 +26,5 @@ ax.set_ylim3d(-1, 4) ax.set_zlim3d(0, 1) -pylab.show() +plt.show() Modified: branches/v0_99_maint/examples/mplot3d/scatter3d_demo.py =================================================================== --- branches/v0_99_maint/examples/mplot3d/scatter3d_demo.py 2009年08月08日 11:25:32 UTC (rev 7427) +++ branches/v0_99_maint/examples/mplot3d/scatter3d_demo.py 2009年08月08日 12:21:29 UTC (rev 7428) @@ -1,21 +1,23 @@ +import numpy as np from mpl_toolkits.mplot3d import Axes3D -import pylab -import random +import matplotlib.pyplot as plt -fig = pylab.figure() + +def randrange(n, vmin, vmax): + return (vmax-vmin)*np.random.rand(n) + vmin + +fig = plt.figure() ax = Axes3D(fig) n = 100 for c, zl, zh in [('r', -50, -25), ('b', -30, -5)]: - xs, ys, zs = zip(* - [(random.randrange(23, 32), - random.randrange(100), - random.randrange(zl, zh) - ) for i in range(n)]) + xs = randrange(n, 23, 32) + ys = randrange(n, 0, 100) + zs = randrange(n, zl, zh) ax.scatter(xs, ys, zs, c=c) ax.set_xlabel('X Label') ax.set_ylabel('Y Label') ax.set_zlabel('Z Label') -pylab.show() +plt.show() Modified: branches/v0_99_maint/examples/mplot3d/surface3d_demo.py =================================================================== --- branches/v0_99_maint/examples/mplot3d/surface3d_demo.py 2009年08月08日 11:25:32 UTC (rev 7427) +++ branches/v0_99_maint/examples/mplot3d/surface3d_demo.py 2009年08月08日 12:21:29 UTC (rev 7428) @@ -1,10 +1,9 @@ from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm -import pylab -import random +import matplotlib.pyplot as plt import numpy as np -fig = pylab.figure() +fig = plt.figure() ax = Axes3D(fig) X = np.arange(-5, 5, 0.25) Y = np.arange(-5, 5, 0.25) @@ -13,5 +12,5 @@ Z = np.sin(R) ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet) -pylab.show() +plt.show() Modified: branches/v0_99_maint/examples/mplot3d/surface3d_demo2.py =================================================================== --- branches/v0_99_maint/examples/mplot3d/surface3d_demo2.py 2009年08月08日 11:25:32 UTC (rev 7427) +++ branches/v0_99_maint/examples/mplot3d/surface3d_demo2.py 2009年08月08日 12:21:29 UTC (rev 7428) @@ -1,9 +1,8 @@ from mpl_toolkits.mplot3d import Axes3D -import pylab -import random +import matplotlib.pyplot as plt import numpy as np -fig = pylab.figure() +fig = plt.figure() ax = Axes3D(fig) u = np.linspace(0, 2 * np.pi, 100) @@ -14,5 +13,5 @@ z = 10 * np.outer(np.ones(np.size(u)), np.cos(v)) ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b') -pylab.show() +plt.show() Modified: branches/v0_99_maint/examples/mplot3d/text3d_demo.py =================================================================== --- branches/v0_99_maint/examples/mplot3d/text3d_demo.py 2009年08月08日 11:25:32 UTC (rev 7427) +++ branches/v0_99_maint/examples/mplot3d/text3d_demo.py 2009年08月08日 12:21:29 UTC (rev 7428) @@ -1,8 +1,7 @@ from mpl_toolkits.mplot3d import Axes3D -import pylab -import random +import matplotlib.pyplot as plt -fig = pylab.figure() +fig = plt.figure() ax = Axes3D(fig) zdirs = (None, 'x', 'y', 'z', (1, 1, 0), (1, 1, 1)) @@ -22,5 +21,5 @@ ax.set_ylabel('Y axis') ax.set_zlabel('Z axis') -pylab.show() +plt.show() Modified: branches/v0_99_maint/examples/mplot3d/wire3d_demo.py =================================================================== --- branches/v0_99_maint/examples/mplot3d/wire3d_demo.py 2009年08月08日 11:25:32 UTC (rev 7427) +++ branches/v0_99_maint/examples/mplot3d/wire3d_demo.py 2009年08月08日 12:21:29 UTC (rev 7428) @@ -1,12 +1,11 @@ from mpl_toolkits.mplot3d import axes3d -import pylab -import random +import matplotlib.pyplot as plt import numpy as np -fig = pylab.figure() +fig = plt.figure() ax = axes3d.Axes3D(fig) X, Y, Z = axes3d.get_test_data(0.05) ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10) -pylab.show() +plt.show() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 7427 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7427&view=rev Author: jdh2358 Date: 2009年08月08日 11:25:32 +0000 (2009年8月08日) Log Message: ----------- Merged revisions 7426 via svnmerge from https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v0_99_maint ........ r7426 | jdh2358 | 2009年08月08日 06:00:41 -0500 (2009年8月08日) | 1 line replace list comps w/ numpy in mplot3d ........ Modified Paths: -------------- trunk/matplotlib/lib/mpl_toolkits/mplot3d/art3d.py trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py trunk/matplotlib/lib/mpl_toolkits/mplot3d/axis3d.py trunk/matplotlib/lib/mpl_toolkits/mplot3d/proj3d.py Property Changed: ---------------- trunk/matplotlib/ Property changes on: trunk/matplotlib ___________________________________________________________________ Modified: svnmerge-integrated - /branches/mathtex:1-7263 /branches/v0_98_5_maint:1-7253 /branches/v0_99_maint:1-7424 + /branches/mathtex:1-7263 /branches/v0_98_5_maint:1-7253 /branches/v0_99_maint:1-7426 Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/art3d.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/mplot3d/art3d.py 2009年08月08日 11:00:41 UTC (rev 7426) +++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/art3d.py 2009年08月08日 11:25:32 UTC (rev 7427) @@ -92,6 +92,7 @@ def set_3d_properties(self, zs=0, zdir='z'): xs = self.get_xdata() ys = self.get_ydata() + try: zs = float(zs) zs = [zs for x in xs] @@ -116,7 +117,7 @@ '''Convert a path to a 3D segment.''' if not iterable(zs): - zs = [zs] * len(path) + zs = np.ones(len(path)) * zs seg = [] pathsegs = path.iter_segments(simplify=False, curves=False) @@ -131,7 +132,7 @@ ''' if not iterable(zs): - zs = [zs] * len(paths) + zs = np.ones(len(paths)) * zs segments = [] for path, pathz in zip(paths, zs): @@ -192,7 +193,8 @@ def set_3d_properties(self, verts, zs=0, zdir='z'): if not iterable(zs): - zs = [zs] * len(verts) + zs = np.ones(len(verts)) * zs + self._segment3d = [juggle_axes(x, y, z, zdir) \ for ((x, y), z) in zip(verts, zs)] self._facecolor3d = Patch.get_facecolor(self) Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2009年08月08日 11:00:41 UTC (rev 7426) +++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2009年08月08日 11:25:32 UTC (rev 7427) @@ -58,7 +58,7 @@ xticks=[], yticks=[], *args, **kwargs) self.M = None - + self._ready = 1 self.mouse_init() self.create_axes() @@ -184,7 +184,7 @@ def autoscale_view(self, scalex=True, scaley=True, scalez=True): # This method looks at the rectanglular volume (see above) # of data and decides how to scale the view portal to fit it. - + self.set_top_view() if not self._ready: return @@ -534,7 +534,7 @@ # Match length if not cbook.iterable(zs): - zs = [zs] * len(xs) + zs = np.ones(len(xs)) * zs lines = Axes.plot(self, xs, ys, *args[argsi:], **kwargs) for line in lines: @@ -552,7 +552,7 @@ By default it will be colored in shades of a solid color, but it also supports color mapping by supplying the *cmap* argument. - + ========== ================================================ Argument Description ========== ================================================ @@ -648,7 +648,7 @@ shade = np.array(shade) mask = ~np.isnan(shade) - if len(shade[mask]) > 0: + if len(shade[mask]) > 0: norm = Normalize(min(shade[mask]), max(shade[mask])) color = color.copy() color[3] = 1 @@ -679,7 +679,7 @@ rstride = kwargs.pop("rstride", 1) cstride = kwargs.pop("cstride", 1) - + had_data = self.has_data() rows, cols = Z.shape @@ -708,7 +708,7 @@ def _3d_extend_contour(self, cset, stride=5): ''' - Extend a contour in 3D by creating + Extend a contour in 3D by creating ''' levels = cset.levels @@ -742,7 +742,7 @@ v1 = np.array(topverts[0][i1]) - np.array(topverts[0][i2]) v2 = np.array(topverts[0][i1]) - np.array(botverts[0][i1]) normals.append(np.cross(v1, v2)) - + colors = self._shade_colors(color, normals) colors2 = self._shade_colors(color, normals) polycol = art3d.Poly3DCollection(polyverts, facecolors=colors, @@ -811,13 +811,13 @@ self.auto_scale_xyz(X, Y, Z, had_data) return cset - + contourf3D = contourf def add_collection3d(self, col, zs=0, zdir='z'): ''' Add a 3d collection object to the plot. - + 2D collection types are converted to a 3D version by modifying the object and adding z coordinate information. @@ -865,7 +865,7 @@ patches = Axes.scatter(self, xs, ys, *args, **kwargs) if not cbook.iterable(zs): is_2d = True - zs = [zs] * len(xs) + zs = np.ones(len(xs)) * zs else: is_2d = False art3d.patch_collection_2d_to_3d(patches, zs=zs, zdir=zdir) @@ -903,8 +903,9 @@ patches = Axes.bar(self, left, height, *args, **kwargs) if not cbook.iterable(zs): - zs = [zs] * len(left) + zs = np.ones(len(left))*zs + verts = [] verts_zs = [] for p, z in zip(patches, zs): Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/axis3d.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axis3d.py 2009年08月08日 11:00:41 UTC (rev 7426) +++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/axis3d.py 2009年08月08日 11:25:32 UTC (rev 7427) @@ -22,6 +22,7 @@ def move_from_center(coord, centers, deltas, axmask=(True, True, True)): '''Return a coordinate that is moved by "deltas" away from the center.''' coord = copy.copy(coord) + #print coord, centers, deltas, axmask for i in range(3): if not axmask[i]: continue @@ -84,7 +85,7 @@ alpha=0.8, facecolor=(1,1,1,0), edgecolor=(1,1,1,0)) - + self.axes._set_artist_props(self.line) self.axes._set_artist_props(self.pane) self.gridlines = art3d.Line3DCollection([], ) @@ -141,7 +142,7 @@ # code from XAxis majorTicks = self.get_major_ticks() majorLocs = self.major.locator() - + # filter locations here so that no extra grid lines are drawn interval = self.get_view_interval() majorLocs = [loc for loc in majorLocs if \ @@ -152,19 +153,20 @@ # Determine bounds minx, maxx, miny, maxy, minz, maxz = self.axes.get_w_lims() - mins = (minx, miny, minz) - maxs = (maxx, maxy, maxz) - centers = [(maxv + minv) / 2 for minv, maxv in zip(mins, maxs)] - deltas = [(maxv - minv) / 12 for minv, maxv in zip(mins, maxs)] - mins = [minv - delta / 4 for minv, delta in zip(mins, deltas)] - maxs = [maxv + delta / 4 for maxv, delta in zip(maxs, deltas)] + mins = np.array((minx, miny, minz)) + maxs = np.array((maxx, maxy, maxz)) + centers = (maxs + mins) / 2. + deltas = (maxs - mins) / 12. + mins = mins - deltas / 4. + maxs = maxs + deltas / 4. # Determine which planes should be visible by the avg z value vals = mins[0], maxs[0], mins[1], maxs[1], mins[2], maxs[2] tc = self.axes.tunit_cube(vals, renderer.M) + #raise RuntimeError('WTF: p1=%s'%p1) avgz = [tc[p1][2] + tc[p2][2] + tc[p3][2] + tc[p4][2] for \ p1, p2, p3, p4 in self._PLANES] - highs = [avgz[2*i] < avgz[2*i+1] for i in range(3)] + highs = np.array([avgz[2*i] < avgz[2*i+1] for i in range(3)]) # Draw plane info = self._AXINFO[self.adir] @@ -178,18 +180,14 @@ self.pane.draw(renderer) # Determine grid lines - minmax = [] - for i, val in enumerate(highs): - if val: - minmax.append(maxs[i]) - else: - minmax.append(mins[i]) + minmax = np.where(highs, maxs, mins) # Draw main axis line juggled = art3d.juggle_axes(0, 2, 1, self.adir) - edgep1 = copy.copy(minmax) + edgep1 = minmax.copy() edgep1[juggled[0]] = get_flip_min_max(edgep1, juggled[0], mins, maxs) - edgep2 = copy.copy(edgep1) + + edgep2 = edgep1.copy() edgep2[juggled[1]] = get_flip_min_max(edgep2, juggled[1], mins, maxs) pep = proj3d.proj_trans_points([edgep1, edgep2], renderer.M) self.line.set_data((pep[0][0], pep[0][1]), (pep[1][0], pep[1][1])) @@ -198,15 +196,17 @@ # Grid points where the planes meet xyz0 = [] for val in majorLocs: - coord = copy.copy(minmax) + coord = minmax.copy() coord[index] = val xyz0.append(coord) # Draw labels dy = pep[1][1] - pep[1][0] dx = pep[0][1] - pep[0][0] - lxyz = [(v1 + v2) / 2 for v1, v2 in zip(edgep1, edgep2)] - labeldeltas = [1.3 * x for x in deltas] + + lxyz = 0.5*(edgep1 + edgep2) + + labeldeltas = 1.3 * deltas lxyz = move_from_center(lxyz, centers, labeldeltas) tlx, tly, tlz = proj3d.proj_transform(lxyz[0], lxyz[1], lxyz[2], \ renderer.M) @@ -293,7 +293,7 @@ def get_data_interval(self): 'return the Interval instance for this axis data limits' return self.axes.xy_dataLim.intervaly - + class ZAxis(Axis): def get_data_interval(self): 'return the Interval instance for this axis data limits' Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/proj3d.py =================================================================== --- trunk/matplotlib/lib/mpl_toolkits/mplot3d/proj3d.py 2009年08月08日 11:00:41 UTC (rev 7426) +++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/proj3d.py 2009年08月08日 11:25:32 UTC (rev 7427) @@ -10,15 +10,8 @@ import numpy as np import numpy.linalg as linalg -def cross(a, b): - """ - Cross product of two vectors - A x B = <Ay*Bz - Az*By, Az*Bx - Ax*Bz, Ax*By - Ay*Bx> - a x b = [a2b3 - a3b2, a3b1 - a1b3, a1b2 - a2b1] - """ - return np.array([a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], \ - a[0]*b[1] - a[1]*b[0]]) + def line2d(p0, p1): """ Return 2D equation of line in the form ax+by+c = 0 @@ -130,9 +123,9 @@ ## old n = n / mod(n) - u = cross(V, n) + u = np.cross(V, n) u = u / mod(u) - v = cross(n, u) + v = np.cross(n, u) Mr = [[u[0],u[1],u[2],0], [v[0],v[1],v[2],0], [n[0],n[1],n[2],0], This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 7426 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7426&view=rev Author: jdh2358 Date: 2009年08月08日 11:00:41 +0000 (2009年8月08日) Log Message: ----------- replace list comps w/ numpy in mplot3d Modified Paths: -------------- branches/v0_99_maint/lib/mpl_toolkits/mplot3d/art3d.py branches/v0_99_maint/lib/mpl_toolkits/mplot3d/axes3d.py branches/v0_99_maint/lib/mpl_toolkits/mplot3d/axis3d.py branches/v0_99_maint/lib/mpl_toolkits/mplot3d/proj3d.py Modified: branches/v0_99_maint/lib/mpl_toolkits/mplot3d/art3d.py =================================================================== --- branches/v0_99_maint/lib/mpl_toolkits/mplot3d/art3d.py 2009年08月08日 06:24:00 UTC (rev 7425) +++ branches/v0_99_maint/lib/mpl_toolkits/mplot3d/art3d.py 2009年08月08日 11:00:41 UTC (rev 7426) @@ -92,6 +92,7 @@ def set_3d_properties(self, zs=0, zdir='z'): xs = self.get_xdata() ys = self.get_ydata() + try: zs = float(zs) zs = [zs for x in xs] @@ -116,7 +117,7 @@ '''Convert a path to a 3D segment.''' if not iterable(zs): - zs = [zs] * len(path) + zs = np.ones(len(path)) * zs seg = [] pathsegs = path.iter_segments(simplify=False, curves=False) @@ -131,7 +132,7 @@ ''' if not iterable(zs): - zs = [zs] * len(paths) + zs = np.ones(len(paths)) * zs segments = [] for path, pathz in zip(paths, zs): @@ -192,7 +193,8 @@ def set_3d_properties(self, verts, zs=0, zdir='z'): if not iterable(zs): - zs = [zs] * len(verts) + zs = np.ones(len(verts)) * zs + self._segment3d = [juggle_axes(x, y, z, zdir) \ for ((x, y), z) in zip(verts, zs)] self._facecolor3d = Patch.get_facecolor(self) Modified: branches/v0_99_maint/lib/mpl_toolkits/mplot3d/axes3d.py =================================================================== --- branches/v0_99_maint/lib/mpl_toolkits/mplot3d/axes3d.py 2009年08月08日 06:24:00 UTC (rev 7425) +++ branches/v0_99_maint/lib/mpl_toolkits/mplot3d/axes3d.py 2009年08月08日 11:00:41 UTC (rev 7426) @@ -58,7 +58,7 @@ xticks=[], yticks=[], *args, **kwargs) self.M = None - + self._ready = 1 self.mouse_init() self.create_axes() @@ -184,7 +184,7 @@ def autoscale_view(self, scalex=True, scaley=True, scalez=True): # This method looks at the rectanglular volume (see above) # of data and decides how to scale the view portal to fit it. - + self.set_top_view() if not self._ready: return @@ -534,7 +534,7 @@ # Match length if not cbook.iterable(zs): - zs = [zs] * len(xs) + zs = np.ones(len(xs)) * zs lines = Axes.plot(self, xs, ys, *args[argsi:], **kwargs) for line in lines: @@ -552,7 +552,7 @@ By default it will be colored in shades of a solid color, but it also supports color mapping by supplying the *cmap* argument. - + ========== ================================================ Argument Description ========== ================================================ @@ -648,7 +648,7 @@ shade = np.array(shade) mask = ~np.isnan(shade) - if len(shade[mask]) > 0: + if len(shade[mask]) > 0: norm = Normalize(min(shade[mask]), max(shade[mask])) color = color.copy() color[3] = 1 @@ -679,7 +679,7 @@ rstride = kwargs.pop("rstride", 1) cstride = kwargs.pop("cstride", 1) - + had_data = self.has_data() rows, cols = Z.shape @@ -708,7 +708,7 @@ def _3d_extend_contour(self, cset, stride=5): ''' - Extend a contour in 3D by creating + Extend a contour in 3D by creating ''' levels = cset.levels @@ -742,7 +742,7 @@ v1 = np.array(topverts[0][i1]) - np.array(topverts[0][i2]) v2 = np.array(topverts[0][i1]) - np.array(botverts[0][i1]) normals.append(np.cross(v1, v2)) - + colors = self._shade_colors(color, normals) colors2 = self._shade_colors(color, normals) polycol = art3d.Poly3DCollection(polyverts, facecolors=colors, @@ -811,13 +811,13 @@ self.auto_scale_xyz(X, Y, Z, had_data) return cset - + contourf3D = contourf def add_collection3d(self, col, zs=0, zdir='z'): ''' Add a 3d collection object to the plot. - + 2D collection types are converted to a 3D version by modifying the object and adding z coordinate information. @@ -865,7 +865,7 @@ patches = Axes.scatter(self, xs, ys, *args, **kwargs) if not cbook.iterable(zs): is_2d = True - zs = [zs] * len(xs) + zs = np.ones(len(xs)) * zs else: is_2d = False art3d.patch_collection_2d_to_3d(patches, zs=zs, zdir=zdir) @@ -903,8 +903,9 @@ patches = Axes.bar(self, left, height, *args, **kwargs) if not cbook.iterable(zs): - zs = [zs] * len(left) + zs = np.ones(len(left))*zs + verts = [] verts_zs = [] for p, z in zip(patches, zs): Modified: branches/v0_99_maint/lib/mpl_toolkits/mplot3d/axis3d.py =================================================================== --- branches/v0_99_maint/lib/mpl_toolkits/mplot3d/axis3d.py 2009年08月08日 06:24:00 UTC (rev 7425) +++ branches/v0_99_maint/lib/mpl_toolkits/mplot3d/axis3d.py 2009年08月08日 11:00:41 UTC (rev 7426) @@ -22,6 +22,7 @@ def move_from_center(coord, centers, deltas, axmask=(True, True, True)): '''Return a coordinate that is moved by "deltas" away from the center.''' coord = copy.copy(coord) + #print coord, centers, deltas, axmask for i in range(3): if not axmask[i]: continue @@ -84,7 +85,7 @@ alpha=0.8, facecolor=(1,1,1,0), edgecolor=(1,1,1,0)) - + self.axes._set_artist_props(self.line) self.axes._set_artist_props(self.pane) self.gridlines = art3d.Line3DCollection([], ) @@ -141,7 +142,7 @@ # code from XAxis majorTicks = self.get_major_ticks() majorLocs = self.major.locator() - + # filter locations here so that no extra grid lines are drawn interval = self.get_view_interval() majorLocs = [loc for loc in majorLocs if \ @@ -152,19 +153,20 @@ # Determine bounds minx, maxx, miny, maxy, minz, maxz = self.axes.get_w_lims() - mins = (minx, miny, minz) - maxs = (maxx, maxy, maxz) - centers = [(maxv + minv) / 2 for minv, maxv in zip(mins, maxs)] - deltas = [(maxv - minv) / 12 for minv, maxv in zip(mins, maxs)] - mins = [minv - delta / 4 for minv, delta in zip(mins, deltas)] - maxs = [maxv + delta / 4 for maxv, delta in zip(maxs, deltas)] + mins = np.array((minx, miny, minz)) + maxs = np.array((maxx, maxy, maxz)) + centers = (maxs + mins) / 2. + deltas = (maxs - mins) / 12. + mins = mins - deltas / 4. + maxs = maxs + deltas / 4. # Determine which planes should be visible by the avg z value vals = mins[0], maxs[0], mins[1], maxs[1], mins[2], maxs[2] tc = self.axes.tunit_cube(vals, renderer.M) + #raise RuntimeError('WTF: p1=%s'%p1) avgz = [tc[p1][2] + tc[p2][2] + tc[p3][2] + tc[p4][2] for \ p1, p2, p3, p4 in self._PLANES] - highs = [avgz[2*i] < avgz[2*i+1] for i in range(3)] + highs = np.array([avgz[2*i] < avgz[2*i+1] for i in range(3)]) # Draw plane info = self._AXINFO[self.adir] @@ -178,18 +180,14 @@ self.pane.draw(renderer) # Determine grid lines - minmax = [] - for i, val in enumerate(highs): - if val: - minmax.append(maxs[i]) - else: - minmax.append(mins[i]) + minmax = np.where(highs, maxs, mins) # Draw main axis line juggled = art3d.juggle_axes(0, 2, 1, self.adir) - edgep1 = copy.copy(minmax) + edgep1 = minmax.copy() edgep1[juggled[0]] = get_flip_min_max(edgep1, juggled[0], mins, maxs) - edgep2 = copy.copy(edgep1) + + edgep2 = edgep1.copy() edgep2[juggled[1]] = get_flip_min_max(edgep2, juggled[1], mins, maxs) pep = proj3d.proj_trans_points([edgep1, edgep2], renderer.M) self.line.set_data((pep[0][0], pep[0][1]), (pep[1][0], pep[1][1])) @@ -198,15 +196,17 @@ # Grid points where the planes meet xyz0 = [] for val in majorLocs: - coord = copy.copy(minmax) + coord = minmax.copy() coord[index] = val xyz0.append(coord) # Draw labels dy = pep[1][1] - pep[1][0] dx = pep[0][1] - pep[0][0] - lxyz = [(v1 + v2) / 2 for v1, v2 in zip(edgep1, edgep2)] - labeldeltas = [1.3 * x for x in deltas] + + lxyz = 0.5*(edgep1 + edgep2) + + labeldeltas = 1.3 * deltas lxyz = move_from_center(lxyz, centers, labeldeltas) tlx, tly, tlz = proj3d.proj_transform(lxyz[0], lxyz[1], lxyz[2], \ renderer.M) @@ -293,7 +293,7 @@ def get_data_interval(self): 'return the Interval instance for this axis data limits' return self.axes.xy_dataLim.intervaly - + class ZAxis(Axis): def get_data_interval(self): 'return the Interval instance for this axis data limits' Modified: branches/v0_99_maint/lib/mpl_toolkits/mplot3d/proj3d.py =================================================================== --- branches/v0_99_maint/lib/mpl_toolkits/mplot3d/proj3d.py 2009年08月08日 06:24:00 UTC (rev 7425) +++ branches/v0_99_maint/lib/mpl_toolkits/mplot3d/proj3d.py 2009年08月08日 11:00:41 UTC (rev 7426) @@ -10,15 +10,8 @@ import numpy as np import numpy.linalg as linalg -def cross(a, b): - """ - Cross product of two vectors - A x B = <Ay*Bz - Az*By, Az*Bx - Ax*Bz, Ax*By - Ay*Bx> - a x b = [a2b3 - a3b2, a3b1 - a1b3, a1b2 - a2b1] - """ - return np.array([a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], \ - a[0]*b[1] - a[1]*b[0]]) + def line2d(p0, p1): """ Return 2D equation of line in the form ax+by+c = 0 @@ -130,9 +123,9 @@ ## old n = n / mod(n) - u = cross(V, n) + u = np.cross(V, n) u = u / mod(u) - v = cross(n, u) + v = np.cross(n, u) Mr = [[u[0],u[1],u[2],0], [v[0],v[1],v[2],0], [n[0],n[1],n[2],0], This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 7425 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7425&view=rev Author: efiring Date: 2009年08月08日 06:24:00 +0000 (2009年8月08日) Log Message: ----------- Merged revisions 7407,7409,7414,7416,7424 via svnmerge from https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v0_99_maint ........ r7407 | jdh2358 | 2009年08月06日 08:51:58 -1000 (2009年8月06日) | 1 line hide colorbar_doc a bit ........ r7409 | ryanmay | 2009年08月06日 09:28:16 -1000 (2009年8月06日) | 1 line Tweak solution for hiding colorbar_doc to sync with trunk. ........ r7414 | jdh2358 | 2009年08月07日 00:15:04 -1000 (2009年8月07日) | 1 line some doc fixes ........ r7416 | jdh2358 | 2009年08月07日 05:40:56 -1000 (2009年8月07日) | 1 line don't fail on window icon load ........ r7424 | efiring | 2009年08月07日 20:07:06 -1000 (2009年8月07日) | 2 lines Restore default colormap behavior: no color (alpha = 0) for masked data ........ Modified Paths: -------------- trunk/matplotlib/doc/_templates/indexsidebar.html trunk/matplotlib/doc/users/annotations.rst trunk/matplotlib/doc/users/artists.rst trunk/matplotlib/doc/users/credits.rst trunk/matplotlib/doc/users/event_handling.rst trunk/matplotlib/doc/users/pyplot_tutorial.rst trunk/matplotlib/doc/users/screenshots.rst trunk/matplotlib/doc/users/whats_new.rst trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py trunk/matplotlib/lib/matplotlib/colors.py Property Changed: ---------------- trunk/matplotlib/ trunk/matplotlib/doc/pyplots/README trunk/matplotlib/doc/sphinxext/gen_gallery.py trunk/matplotlib/doc/sphinxext/gen_rst.py trunk/matplotlib/examples/misc/multiprocess.py trunk/matplotlib/examples/mplot3d/contour3d_demo.py trunk/matplotlib/examples/mplot3d/contourf3d_demo.py trunk/matplotlib/examples/mplot3d/polys3d_demo.py trunk/matplotlib/examples/mplot3d/scatter3d_demo.py trunk/matplotlib/examples/mplot3d/surface3d_demo.py trunk/matplotlib/examples/mplot3d/wire3d_demo.py trunk/matplotlib/lib/matplotlib/sphinxext/mathmpl.py trunk/matplotlib/lib/matplotlib/sphinxext/only_directives.py trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py Property changes on: trunk/matplotlib ___________________________________________________________________ Modified: svnmerge-integrated - /branches/mathtex:1-7263 /branches/v0_98_5_maint:1-7253 /branches/v0_99_maint:1-7404 + /branches/mathtex:1-7263 /branches/v0_98_5_maint:1-7253 /branches/v0_99_maint:1-7424 Modified: svn:mergeinfo - /branches/v0_91_maint:5753-5771 /branches/v0_98_5_maint:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint:7338,7393,7395-7404 + /branches/v0_91_maint:5753-5771 /branches/v0_98_5_maint:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint:7338,7393,7395-7404,7407-7424 Modified: trunk/matplotlib/doc/_templates/indexsidebar.html =================================================================== --- trunk/matplotlib/doc/_templates/indexsidebar.html 2009年08月08日 06:07:06 UTC (rev 7424) +++ trunk/matplotlib/doc/_templates/indexsidebar.html 2009年08月08日 06:24:00 UTC (rev 7425) @@ -29,7 +29,7 @@ and join the matplotlib mailing <a href="http://sourceforge.net/mail/?group_id=80706">lists</a>. The <a href="{{ pathto('search') }}">search</a> tool searches all of -the documentation, including full text search of almost 300 complete +the documentation, including full text search of over 350 complete examples which exercise almost every corner of matplotlib.</p> <p>You can file bugs, patches and feature requests on the Property changes on: trunk/matplotlib/doc/pyplots/README ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_98_5_maint/doc/pyplots/README:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint/doc/pyplots/README:7338,7393,7395-7404 + /branches/v0_98_5_maint/doc/pyplots/README:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint/doc/pyplots/README:7338,7393,7395-7404,7407-7424 Property changes on: trunk/matplotlib/doc/sphinxext/gen_gallery.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/doc/_templates/gen_gallery.py:5753-5771 /branches/v0_98_5_maint/doc/sphinxext/gen_gallery.py:6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint/doc/sphinxext/gen_gallery.py:7338,7393,7395-7404 + /branches/v0_91_maint/doc/_templates/gen_gallery.py:5753-5771 /branches/v0_98_5_maint/doc/sphinxext/gen_gallery.py:6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint/doc/sphinxext/gen_gallery.py:7338,7393,7395-7404,7407-7424 Property changes on: trunk/matplotlib/doc/sphinxext/gen_rst.py ___________________________________________________________________ Modified: svn:mergeinfo - /branches/v0_91_maint/doc/examples/gen_rst.py:5753-5771 /branches/v0_98_5_maint/doc/sphinxext/gen_rst.py:6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint/doc/sphinxext/gen_rst.py:7338,7393,7395-7404 + /branches/v0_91_maint/doc/examples/gen_rst.py:5753-5771 /branches/v0_98_5_maint/doc/sphinxext/gen_rst.py:6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6911-6912,6915-6916,6918,6920-6925,6927-6928,6934,6941,6946,6948,6950,6952,6960,6972,6984-6985,6990,6995,6997-7001,7014,7016,7018,7024-7025,7033,7035,7042,7072,7080,7176,7209-7211,7227,7245 /branches/v0_99_maint/doc/sphinxext/gen_rst.py:7338,7393,7395-7404,7407-7424 Modified: trunk/matplotlib/doc/users/annotations.rst =================================================================== --- trunk/matplotlib/doc/users/annotations.rst 2009年08月08日 06:07:06 UTC (rev 7424) +++ trunk/matplotlib/doc/users/annotations.rst 2009年08月08日 06:24:00 UTC (rev 7425) @@ -78,6 +78,4 @@ .. plot:: pyplots/annotation_polar.py :include-source: -See the `annotations demo -<http://matplotlib.sf.net/examples/pylab_examples/annotation_demo.py>`_ for more -examples. +For more on all the wild and wonderful things you can do with annotations, including fancy arrows, see :ref:`plotting-guide-annotation` and :ref:`pylab_examples-annotation_demo`. Modified: trunk/matplotlib/doc/users/artists.rst =================================================================== --- trunk/matplotlib/doc/users/artists.rst 2009年08月08日 06:07:06 UTC (rev 7424) +++ trunk/matplotlib/doc/users/artists.rst 2009年08月08日 06:24:00 UTC (rev 7425) @@ -19,27 +19,7 @@ and laying out the figure, text, and lines. The typical user will spend 95% of his time working with the ``Artists``. -There are two types of ``Artists``: primitives and containers. The -primitives represent the standard graphical objects we want to paint -onto our canvas: :class:`~matplotlib.lines.Line2D`, -:class:`~matplotlib.patches.Rectangle`, -:class:`~matplotlib.text.Text`, :class:`~matplotlib.image.AxesImage`, -etc., and the containers are places to put them -(:class:`~matplotlib.axis.Axis`, :class:`~matplotlib.axes.Axes` and -:class:`~matplotlib.figure.Figure`). The standard use is to create a -:class:`~matplotlib.figure.Figure` instance, use the ``Figure`` to -create one or more :class:`~matplotlib.axes.Axes` or -:class:`~matplotlib.axes.Subplot` instances, and use the ``Axes`` -instance helper methods to create the primitives. In the example -below, we create a ``Figure`` instance using -:func:`matplotlib.pyplot.figure`, which is a convenience method for -instantiating ``Figure`` instances and connecting them with your user -interface or drawing toolkit ``FigureCanvas``. As we will discuss -below, this is not necessary, and you can work directly with -PostScript, PDF Gtk+, or wxPython ``FigureCanvas`` instances. For -example, instantiate your ``Figures`` directly and connect them -yourselves, but since we are focusing here on the ``Artist`` API we'll let -:mod:`~matplotlib.pyplot` handle some of those details for us:: +There are two types of ``Artists``: primitives and containers. The primitives represent the standard graphical objects we want to paint onto our canvas: :class:`~matplotlib.lines.Line2D`, :class:`~matplotlib.patches.Rectangle`, :class:`~matplotlib.text.Text`, :class:`~matplotlib.image.AxesImage`, etc., and the containers are places to put them (:class:`~matplotlib.axis.Axis`, :class:`~matplotlib.axes.Axes` and :class:`~matplotlib.figure.Figure`). The standard use is to create a :class:`~matplotlib.figure.Figure` instance, use the ``Figure`` to create one or more :class:`~matplotlib.axes.Axes` or :class:`~matplotlib.axes.Subplot` instances, and use the ``Axes`` instance helper methods to create the primitives. In the example below, we create a ``Figure`` instance using :func:`matplotlib.pyplot.figure`, which is a convenience method for instantiating ``Figure`` instances and connecting them with your user interface or drawing toolkit ``FigureCanvas``. As we will discuss below, this is not necessary -- you can work directly with PostScript, PDF Gtk+, or wxPython ``FigureCanvas`` instances, instantiate your ``Figures`` directly and connect them yourselves -- but since we are focusing here on the ``Artist`` API we'll let :mod:`~matplotlib.pyplot` handle some of those details for us:: import matplotlib.pyplot as plt fig = plt.figure() @@ -85,7 +65,7 @@ <matplotlib.axes.Axes.lines>` list. In the interactive `ipython <http://ipython.scipy.org/>`_ session below, you can see that the ``Axes.lines`` list is length one and contains the same line that was -returned by the ``line, = ax.plot(x, y, 'o')`` call: +returned by the ``line, = ax.plot...`` call: .. sourcecode:: ipython @@ -536,20 +516,7 @@ :class:`~matplotlib.ticker.Formatter` instances which control where the ticks are placed and how they are represented as strings. -Each ``Axis`` object contains a :attr:`~matplotlib.axis.Axis.label` -attribute (this is what the :mod:`~matplotlib.pylab` calls to -:func:`~matplotlib.pylab.xlabel` and :func:`~matplotlib.pylab.ylabel` -set) as well as a list of major and minor ticks. The ticks are -:class:`~matplotlib.axis.XTick` and :class:`~matplotlib.axis.YTick` -instances, which contain the actual line and text primitives that -render the ticks and ticklabels. Because the ticks are dynamically -created as needed (eg. when panning and zooming), you should access -the lists of major and minor ticks through their accessor methods -:meth:`~matplotlib.axis.Axis.get_major_ticks` and -:meth:`~matplotlib.axis.Axis.get_minor_ticks`. Although the ticks -contain all the primitives and will be covered below, the ``Axis`` methods -contain accessor methods to return the tick lines, tick labels, tick -locations etc.: +Each ``Axis`` object contains a :attr:`~matplotlib.axis.Axis.label` attribute (this is what :mod:`~matplotlib.pylab` modifies in calls to :func:`~matplotlib.pylab.xlabel` and :func:`~matplotlib.pylab.ylabel`) as well as a list of major and minor ticks. The ticks are :class:`~matplotlib.axis.XTick` and :class:`~matplotlib.axis.YTick` instances, which contain the actual line and text primitives that render the ticks and ticklabels. Because the ticks are dynamically created as needed (eg. when panning and zooming), you should access the lists of major and minor ticks through their accessor methods :meth:`~matplotlib.axis.Axis.get_major_ticks` and :meth:`~matplotlib.axis.Axis.get_minor_ticks`. Although the ticks contain all the primitives and will be covered below, the ``Axis`` methods contain accessor methods to return the tick lines, tick labels, tick locations etc.: .. sourcecode:: ipython @@ -636,7 +603,7 @@ label2On boolean which determines whether to draw tick label ============== ========================================================== -Here is an example which sets the formatter for the upper ticks with +Here is an example which sets the formatter for the right side ticks with dollar signs and colors them green on the right side of the yaxis .. plot:: pyplots/dollar_ticks.py Modified: trunk/matplotlib/doc/users/credits.rst =================================================================== --- trunk/matplotlib/doc/users/credits.rst 2009年08月08日 06:07:06 UTC (rev 7424) +++ trunk/matplotlib/doc/users/credits.rst 2009年08月08日 06:24:00 UTC (rev 7425) @@ -16,9 +16,9 @@ Jeremy O'Donoghue wrote the wx backend -Andrew Straw - provided much of the log scaling architecture, the fill command, PIL - support for imshow, and provided many examples +Andrew Straw provided much of the log scaling architecture, the fill + command, PIL support for imshow, and provided many examples. He + also wrote the support for dropped axis spines. Charles Twardy provided the impetus code for the legend class and has made @@ -28,7 +28,6 @@ made many enhancements to errorbar to support x and y errorbar plots, and added a number of new marker types to plot. - John Gill wrote the table class and examples, helped with support for auto-legend placement, and added support for legending scatter @@ -133,7 +132,7 @@ most aspects of matplotlib. Daishi Harada - added support for "Dashed Text". See ` dashpointlabel.py + added support for "Dashed Text". See `dashpointlabel.py <examples/pylab_examples/dashpointlabel.py>`_ and :class:`~matplotlib.text.TextWithDash`. @@ -147,11 +146,10 @@ Charlie Moad - contributed work to matplotlib's Cocoa support and does the binary - builds and releases. + contributed work to matplotlib's Cocoa support and has done a lot of work on the OSX and win32 binary releases. -Jouni K. Seppaenen - wrote the PDF backend. +Jouni K. Seppaenen wrote the PDF backend and contributed numerous + fixes to the code, to tex support and to the get_sample_data handler Paul Kienzle improved the picking infrastruture for interactive plots, and with @@ -171,4 +169,7 @@ matplotlib, and Jonathon Taylor and Reinier Heeres ported it to the refactored transform trunk. - +Jae-Joon Lee implemented fancy arrows and boxes, rewrote the legend + support to handle multiple columns and fancy text boxes, wrote the + axes grid toolkit, and has made numerous contributions to the code + and documentation \ No newline at end of file Modified: trunk/matplotlib/doc/users/event_handling.rst =================================================================== --- trunk/matplotlib/doc/users/event_handling.rst 2009年08月08日 06:07:06 UTC (rev 7424) +++ trunk/matplotlib/doc/users/event_handling.rst 2009年08月08日 06:24:00 UTC (rev 7425) @@ -1,555 +1,555 @@ -.. _event-handling-tutorial: - -************************** -Event handling and picking -************************** - -matplotlib works with 5 user interface toolkits (wxpython, tkinter, -qt, gtk and fltk) and in order to support features like interactive -panning and zooming of figures, it is helpful to the developers to -have an API for interacting with the figure via key presses and mouse -movements that is "GUI neutral" so we don't have to repeat a lot of -code across the different user interfaces. Although the event -handling API is GUI neutral, it is based on the GTK model, which was -the first user interface matplotlib supported. The events that are -triggered are also a bit richer vis-a-vis matplotlib than standard GUI -events, including information like which :class:`matplotlib.axes.Axes` -the event occurred in. The events also understand the matplotlib -coordinate system, and report event locations in both pixel and data -coordinates. - -.. _event-connections: - -Event connections -================= - -To receive events, you need to write a callback function and then -connect your function to the event manager, which is part of the -:class:`~matplotlib.backend_bases.FigureCanvasBase`. Here is a simple -example that prints the location of the mouse click and which button -was pressed:: - - fig = plt.figure() - ax = fig.add_subplot(111) - ax.plot(np.random.rand(10)) - - def onclick(event): - print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%( - event.button, event.x, event.y, event.xdata, event.ydata) - - cid = fig.canvas.mpl_connect('button_press_event', onclick) - -The ``FigureCanvas`` method -:meth:`~matplotlib.backend_bases.FigureCanvasBase.mpl_connect` returns -a connection id which is simply an integer. When you want to -disconnect the callback, just call:: - - fig.canvas.mpl_disconnect(cid) - -Here are the events that you can connect to, the class instances that -are sent back to you when the event occurs, and the event descriptions - - -======================= ====================================================================================== -Event name Class and description -======================= ====================================================================================== -'button_press_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse button is pressed -'button_release_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse button is released -'draw_event' :class:`~matplotlib.backend_bases.DrawEvent` - canvas draw -'key_press_event' :class:`~matplotlib.backend_bases.KeyEvent` - key is pressed -'key_release_event' :class:`~matplotlib.backend_bases.KeyEvent` - key is released -'motion_notify_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse motion -'pick_event' :class:`~matplotlib.backend_bases.PickEvent` - an object in the canvas is selected -'resize_event' :class:`~matplotlib.backend_bases.ResizeEvent` - figure canvas is resized -'scroll_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse scroll wheel is rolled -'figure_enter_event' :class:`~matplotlib.backend_bases.LocationEvent` - mouse enters a new figure -'figure_leave_event' :class:`~matplotlib.backend_bases.LocationEvent` - mouse leaves a figure -'axes_enter_event' :class:`~matplotlib.backend_bases.LocationEvent` - mouse enters a new axes -'axes_leave_event' :class:`~matplotlib.backend_bases.LocationEvent` - mouse leaves an axes -======================= ====================================================================================== - -.. _event-attributes: - -Event attributes -================ - -All matplotlib events inherit from the base class -:class:`matplotlib.backend_bases.Event`, which store the attributes: - - ``name`` - the event name - - ``canvas`` - the FigureCanvas instance generating the event - - ``guiEvent`` - the GUI event that triggered the matplotlib event - - -The most common events that are the bread and butter of event handling -are key press/release events and mouse press/release and movement -events. The :class:`~matplotlib.backend_bases.KeyEvent` and -:class:`~matplotlib.backend_bases.MouseEvent` classes that handle -these events are both derived from the LocationEvent, which has the -following attributes - - ``x`` - x position - pixels from left of canvas - - ``y`` - y position - pixels from bottom of canvas - - ``inaxes`` - the :class:`~matplotlib.axes.Axes` instance if mouse is over axes - - ``xdata`` - x coord of mouse in data coords - - ``ydata`` - y coord of mouse in data coords - -Let's look a simple example of a canvas, where a simple line segment -is created every time a mouse is pressed:: - - class LineBuilder: - def __init__(self, line): - self.line = line - self.xs = list(line.get_xdata()) - self.ys = list(line.get_ydata()) - self.cid = line.figure.canvas.mpl_connect('button_press_event', self) - - def __call__(self, event): - print 'click', event - if event.inaxes!=self.line.axes: return - self.xs.append(event.xdata) - self.ys.append(event.ydata) - self.line.set_data(self.xs, self.ys) - self.line.figure.canvas.draw() - - fig = plt.figure() - ax = fig.add_subplot(111) - ax.set_title('click to build line segments') - line, = ax.plot([0], [0]) # empty line - linebuilder = LineBuilder(line) - - - -The :class:`~matplotlib.backend_bases.MouseEvent` that we just used is a -:class:`~matplotlib.backend_bases.LocationEvent`, so we have access to -the data and pixel coordinates in event.x and event.xdata. In -addition to the ``LocationEvent`` attributes, it has - - ``button`` - button pressed None, 1, 2, 3, 'up', 'down' (up and down are used for scroll events) - - ``key`` - the key pressed: None, chr(range(255), 'shift', 'win', or 'control' - -Draggable rectangle exercise ----------------------------- - -Write draggable rectangle class that is initialized with a -:class:`~matplotlib.patches.Rectangle` instance but will move its x,y -location when dragged. Hint: you will need to store the orginal -``xy`` location of the rectangle which is stored as rect.xy and -connect to the press, motion and release mouse events. When the mouse -is pressed, check to see if the click occurs over your rectangle (see -:meth:`matplotlib.patches.Rectangle.contains`) and if it does, store -the rectangle xy and the location of the mouse click in data coords. -In the motion event callback, compute the deltax and deltay of the -mouse movement, and add those deltas to the origin of the rectangle -you stored. The redraw the figure. On the button release event, just -reset all the button press data you stored as None. - -Here is the solution:: - - import numpy as np - import matplotlib.pyplot as plt - - class DraggableRectangle: - def __init__(self, rect): - self.rect = rect - self.press = None - - def connect(self): - 'connect to all the events we need' - self.cidpress = self.rect.figure.canvas.mpl_connect( - 'button_press_event', self.on_press) - self.cidrelease = self.rect.figure.canvas.mpl_connect( - 'button_release_event', self.on_release) - self.cidmotion = self.rect.figure.canvas.mpl_connect( - 'motion_notify_event', self.on_motion) - - def on_press(self, event): - 'on button press we will see if the mouse is over us and store some data' - if event.inaxes != self.rect.axes: return - - contains, attrd = self.rect.contains(event) - if not contains: return - print 'event contains', self.rect.xy - x0, y0 = self.rect.xy - self.press = x0, y0, event.xdata, event.ydata - - def on_motion(self, event): - 'on motion we will move the rect if the mouse is over us' - if self.press is None: return - if event.inaxes != self.rect.axes: return - x0, y0, xpress, ypress = self.press - dx = event.xdata - xpress - dy = event.ydata - ypress - #print 'x0=%f, xpress=%f, event.xdata=%f, dx=%f, x0+dx=%f'%(x0, xpress, event.xdata, dx, x0+dx) - self.rect.set_x(x0+dx) - self.rect.set_y(y0+dy) - - self.rect.figure.canvas.draw() - - - def on_release(self, event): - 'on release we reset the press data' - self.press = None - self.rect.figure.canvas.draw() - - def disconnect(self): - 'disconnect all the stored connection ids' - self.rect.figure.canvas.mpl_disconnect(self.cidpress) - self.rect.figure.canvas.mpl_disconnect(self.cidrelease) - self.rect.figure.canvas.mpl_disconnect(self.cidmotion) - - fig = plt.figure() - ax = fig.add_subplot(111) - rects = ax.bar(range(10), 20*np.random.rand(10)) - drs = [] - for rect in rects: - dr = DraggableRectangle(rect) - dr.connect() - drs.append(dr) - - plt.show() - - -**Extra credit**: use the animation blit techniques discussed in the -`animations recipe -<http://www.scipy.org/Cookbook/Matplotlib/Animations>`_ to make the -animated drawing faster and smoother. - -Extra credit solution:: - - # draggable rectangle with the animation blit techniques; see - # http://www.scipy.org/Cookbook/Matplotlib/Animations - import numpy as np - import matplotlib.pyplot as plt - - class DraggableRectangle: - lock = None # only one can be animated at a time - def __init__(self, rect): - self.rect = rect - self.press = None - self.background = None - - def connect(self): - 'connect to all the events we need' - self.cidpress = self.rect.figure.canvas.mpl_connect( - 'button_press_event', self.on_press) - self.cidrelease = self.rect.figure.canvas.mpl_connect( - 'button_release_event', self.on_release) - self.cidmotion = self.rect.figure.canvas.mpl_connect( - 'motion_notify_event', self.on_motion) - - def on_press(self, event): - 'on button press we will see if the mouse is over us and store some data' - if event.inaxes != self.rect.axes: return - if DraggableRectangle.lock is not None: return - contains, attrd = self.rect.contains(event) - if not contains: return - print 'event contains', self.rect.xy - x0, y0 = self.rect.xy - self.press = x0, y0, event.xdata, event.ydata - DraggableRectangle.lock = self - - # draw everything but the selected rectangle and store the pixel buffer - canvas = self.rect.figure.canvas - axes = self.rect.axes - self.rect.set_animated(True) - canvas.draw() - self.background = canvas.copy_from_bbox(self.rect.axes.bbox) - - # now redraw just the rectangle - axes.draw_artist(self.rect) - - # and blit just the redrawn area - canvas.blit(axes.bbox) - - def on_motion(self, event): - 'on motion we will move the rect if the mouse is over us' - if DraggableRectangle.lock is not self: - return - if event.inaxes != self.rect.axes: return - x0, y0, xpress, ypress = self.press - dx = event.xdata - xpress - dy = event.ydata - ypress - self.rect.set_x(x0+dx) - self.rect.set_y(y0+dy) - - canvas = self.rect.figure.canvas - axes = self.rect.axes - # restore the background region - canvas.restore_region(self.background) - - # redraw just the current rectangle - axes.draw_artist(self.rect) - - # blit just the redrawn area - canvas.blit(axes.bbox) - - def on_release(self, event): - 'on release we reset the press data' - if DraggableRectangle.lock is not self: - return - - self.press = None - DraggableRectangle.lock = None - - # turn off the rect animation property and reset the background - self.rect.set_animated(False) - self.background = None - - # redraw the full figure - self.rect.figure.canvas.draw() - - def disconnect(self): - 'disconnect all the stored connection ids' - self.rect.figure.canvas.mpl_disconnect(self.cidpress) - self.rect.figure.canvas.mpl_disconnect(self.cidrelease) - self.rect.figure.canvas.mpl_disconnect(self.cidmotion) - - fig = plt.figure() - ax = fig.add_subplot(111) - rects = ax.bar(range(10), 20*np.random.rand(10)) - drs = [] - for rect in rects: - dr = DraggableRectangle(rect) - dr.connect() - drs.append(dr) - - plt.show() - - -.. _enter-leave-events: - -Mouse enter and leave -====================== - -If you want to be notified when the mouse enters or leaves a figure or -axes, you can connect to the figure/axes enter/leave events. Here is -a simple example that changes the colors of the axes and figure -background that the mouse is over:: - - """ - Illustrate the figure and axes enter and leave events by changing the - frame colors on enter and leave - """ - import matplotlib.pyplot as plt - - def enter_axes(event): - print 'enter_axes', event.inaxes - event.inaxes.patch.set_facecolor('yellow') - event.canvas.draw() - - def leave_axes(event): - print 'leave_axes', event.inaxes - event.inaxes.patch.set_facecolor('white') - event.canvas.draw() - - def enter_figure(event): - print 'enter_figure', event.canvas.figure - event.canvas.figure.patch.set_facecolor('red') - event.canvas.draw() - - def leave_figure(event): - print 'leave_figure', event.canvas.figure - event.canvas.figure.patch.set_facecolor('grey') - event.canvas.draw() - - fig1 = plt.figure() - fig1.suptitle('mouse hover over figure or axes to trigger events') - ax1 = fig1.add_subplot(211) - ax2 = fig1.add_subplot(212) - - fig1.canvas.mpl_connect('figure_enter_event', enter_figure) - fig1.canvas.mpl_connect('figure_leave_event', leave_figure) - fig1.canvas.mpl_connect('axes_enter_event', enter_axes) - fig1.canvas.mpl_connect('axes_leave_event', leave_axes) - - fig2 = plt.figure() - fig2.suptitle('mouse hover over figure or axes to trigger events') - ax1 = fig2.add_subplot(211) - ax2 = fig2.add_subplot(212) - - fig2.canvas.mpl_connect('figure_enter_event', enter_figure) - fig2.canvas.mpl_connect('figure_leave_event', leave_figure) - fig2.canvas.mpl_connect('axes_enter_event', enter_axes) - fig2.canvas.mpl_connect('axes_leave_event', leave_axes) - - plt.show() - - - -.. _object-picking: - -Object picking -============== - -You can enable picking by setting the ``picker`` property of an -:class:`~matplotlib.artist.Artist` (eg a matplotlib -:class:`~matplotlib.lines.Line2D`, :class:`~matplotlib.text.Text`, -:class:`~matplotlib.patches.Patch`, :class:`~matplotlib.patches.Polygon`, -:class:`~matplotlib.patches.AxesImage`, etc...) - -There are a variety of meanings of the ``picker`` property: - - ``None`` - picking is disabled for this artist (default) - - ``boolean`` - if True then picking will be enabled and the artist will fire a - pick event if the mouse event is over the artist - - ``float`` - if picker is a number it is interpreted as an epsilon tolerance in - points and the the artist will fire off an event if its data is - within epsilon of the mouse event. For some artists like lines - and patch collections, the artist may provide additional data to - the pick event that is generated, eg the indices of the data - within epsilon of the pick event. - - ``function`` - if picker is callable, it is a user supplied function which - determines whether the artist is hit by the mouse event. The - signature is ``hit, props = picker(artist, mouseevent)`` to - determine the hit test. If the mouse event is over the artist, - return ``hit=True`` and props is a dictionary of properties you - want added to the :class:`~matplotlib.backend_bases.PickEvent` - attributes - - -After you have enabled an artist for picking by setting the ``picker`` -property, you need to connect to the figure canvas pick_event to get -pick callbacks on mouse press events. Eg:: - - def pick_handler(event): - mouseevent = event.mouseevent - artist = event.artist - # now do something with this... - - -The :class:`~matplotlib.backend_bases.PickEvent` which is passed to -your callback is always fired with two attributes: - - ``mouseevent`` the mouse event that generate the pick event. The - mouse event in turn has attributes like ``x`` and ``y`` (the - coords in display space, eg pixels from left, bottom) and xdata, - ydata (the coords in data space). Additionally, you can get - information about which buttons were pressed, which keys were - pressed, which :class:`~matplotlib.axes.Axes` the mouse is over, - etc. See :class:`matplotlib.backend_bases.MouseEvent` for - details. - - ``artist`` - the :class:`~matplotlib.artist.Artist` that generated the pick - event. - -Additionally, certain artists like :class:`~matplotlib.lines.Line2D` -and :class:`~matplotlib.collections.PatchCollection` may attach -additional meta data like the indices into the data that meet the -picker criteria (eg all the points in the line that are within the -specified epsilon tolerance) - -Simple picking example ----------------------- - -In the example below, we set the line picker property to a scalar, so -it represents a tolerance in points (72 points per inch). The onpick -callback function will be called when the pick event it within the -tolerance distance from the line, and has the indices of the data -vertices that are within the pick distance tolerance. Our onpick -callback function simply prints the data that are under the pick -location. Different matplotlib Artists can attach different data to -the PickEvent. For example, ``Line2D`` attaches the ind property, -which are the indices into the line data under the pick point. See -:meth:`~matplotlib.lines.Line2D.pick` for details on the ``PickEvent`` -properties of the line. Here is the code:: - - import numpy as np - import matplotlib.pyplot as plt - - fig = plt.figure() - ax = fig.add_subplot(111) - ax.set_title('click on points') - - line, = ax.plot(np.random.rand(100), 'o', picker=5) # 5 points tolerance - - def onpick(event): - thisline = event.artist - xdata = thisline.get_xdata() - ydata = thisline.get_ydata() - ind = event.ind - print 'onpick points:', zip(xdata[ind], ydata[ind]) - - fig.canvas.mpl_connect('pick_event', onpick) - - plt.show() - - -Picking exercise ----------------- - -Create a data set of 100 arrays of 1000 Gaussian random numbers and -compute the sample mean and standard deviation of each of them (hint: -numpy arrays have a mean and std method) and make a xy marker plot of -the 100 means vs the 100 standard deviations. Connect the line -created by the plot command to the pick event, and plot the original -time series of the data that generated the clicked on points. If more -than one point is within the tolerance of the clicked on point, you -can use multiple subplots to plot the multiple time series. - -Exercise solution:: - - """ - compute the mean and stddev of 100 data sets and plot mean vs stddev. - When you click on one of the mu, sigma points, plot the raw data from - the dataset that generated the mean and stddev - """ - import numpy as np - import matplotlib.pyplot as plt - - X = np.random.rand(100, 1000) - xs = np.mean(X, axis=1) - ys = np.std(X, axis=1) - - fig = plt.figure() - ax = fig.add_subplot(111) - ax.set_title('click on point to plot time series') - line, = ax.plot(xs, ys, 'o', picker=5) # 5 points tolerance - - - def onpick(event): - - if event.artist!=line: return True - - N = len(event.ind) - if not N: return True - - - figi = plt.figure() - for subplotnum, dataind in enumerate(event.ind): - ax = figi.add_subplot(N,1,subplotnum+1) - ax.plot(X[dataind]) - ax.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f'%(xs[dataind], ys[dataind]), - transform=ax.transAxes, va='top') - ax.set_ylim(-0.5, 1.5) - figi.show() - return True - - fig.canvas.mpl_connect('pick_event', onpick) - +.. _event-handling-tutorial: + +************************** +Event handling and picking +************************** + +matplotlib works with 6 user interface toolkits (wxpython, tkinter, +qt, gtk, fltk abd macosx) and in order to support features like interactive +panning and zooming of figures, it is helpful to the developers to +have an API for interacting with the figure via key presses and mouse +movements that is "GUI neutral" so we don't have to repeat a lot of +code across the different user interfaces. Although the event +handling API is GUI neutral, it is based on the GTK model, which was +the first user interface matplotlib supported. The events that are +triggered are also a bit richer vis-a-vis matplotlib than standard GUI +events, including information like which :class:`matplotlib.axes.Axes` +the event occurred in. The events also understand the matplotlib +coordinate system, and report event locations in both pixel and data +coordinates. + +.. _event-connections: + +Event connections +================= + +To receive events, you need to write a callback function and then +connect your function to the event manager, which is part of the +:class:`~matplotlib.backend_bases.FigureCanvasBase`. Here is a simple +example that prints the location of the mouse click and which button +was pressed:: + + fig = plt.figure() + ax = fig.add_subplot(111) + ax.plot(np.random.rand(10)) + + def onclick(event): + print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%( + event.button, event.x, event.y, event.xdata, event.ydata) + + cid = fig.canvas.mpl_connect('button_press_event', onclick) + +The ``FigureCanvas`` method +:meth:`~matplotlib.backend_bases.FigureCanvasBase.mpl_connect` returns +a connection id which is simply an integer. When you want to +disconnect the callback, just call:: + + fig.canvas.mpl_disconnect(cid) + +Here are the events that you can connect to, the class instances that +are sent back to you when the event occurs, and the event descriptions + + +======================= ====================================================================================== +Event name Class and description +======================= ====================================================================================== +'button_press_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse button is pressed +'button_release_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse button is released +'draw_event' :class:`~matplotlib.backend_bases.DrawEvent` - canvas draw +'key_press_event' :class:`~matplotlib.backend_bases.KeyEvent` - key is pressed +'key_release_event' :class:`~matplotlib.backend_bases.KeyEvent` - key is released +'motion_notify_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse motion +'pick_event' :class:`~matplotlib.backend_bases.PickEvent` - an object in the canvas is selected +'resize_event' :class:`~matplotlib.backend_bases.ResizeEvent` - figure canvas is resized +'scroll_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse scroll wheel is rolled +'figure_enter_event' :class:`~matplotlib.backend_bases.LocationEvent` - mouse enters a new figure +'figure_leave_event' :class:`~matplotlib.backend_bases.LocationEvent` - mouse leaves a figure +'axes_enter_event' :class:`~matplotlib.backend_bases.LocationEvent` - mouse enters a new axes +'axes_leave_event' :class:`~matplotlib.backend_bases.LocationEvent` - mouse leaves an axes +======================= ====================================================================================== + +.. _event-attributes: + +Event attributes +================ + +All matplotlib events inherit from the base class +:class:`matplotlib.backend_bases.Event`, which store the attributes: + + ``name`` + the event name + + ``canvas`` + the FigureCanvas instance generating the event + + ``guiEvent`` + the GUI event that triggered the matplotlib event + + +The most common events that are the bread and butter of event handling +are key press/release events and mouse press/release and movement +events. The :class:`~matplotlib.backend_bases.KeyEvent` and +:class:`~matplotlib.backend_bases.MouseEvent` classes that handle +these events are both derived from the LocationEvent, which has the +following attributes + + ``x`` + x position - pixels from left of canvas + + ``y`` + y position - pixels from bottom of canvas + + ``inaxes`` + the :class:`~matplotlib.axes.Axes` instance if mouse is over axes + + ``xdata`` + x coord of mouse in data coords + + ``ydata`` + y coord of mouse in data coords + +Let's look a simple example of a canvas, where a simple line segment +is created every time a mouse is pressed:: + + class LineBuilder: + def __init__(self, line): + self.line = line + self.xs = list(line.get_xdata()) + self.ys = list(line.get_ydata()) + self.cid = line.figure.canvas.mpl_connect('button_press_event', self) + + def __call__(self, event): + print 'click', event + if event.inaxes!=self.line.axes: return + self.xs.append(event.xdata) + self.ys.append(event.ydata) + self.line.set_data(self.xs, self.ys) + self.line.figure.canvas.draw() + + fig = plt.figure() + ax = fig.add_subplot(111) + ax.set_title('click to build line segments') + line, = ax.plot([0], [0]) # empty line + linebuilder = LineBuilder(line) + + + +The :class:`~matplotlib.backend_bases.MouseEvent` that we just used is a +:class:`~matplotlib.backend_bases.LocationEvent`, so we have access to +the data and pixel coordinates in event.x and event.xdata. In +addition to the ``LocationEvent`` attributes, it has + + ``button`` + button pressed None, 1, 2, 3, 'up', 'down' (up and down are used for scroll events) + + ``key`` + the key pressed: None, any character, 'shift', 'win', or 'control' + +Draggable rectangle exercise +---------------------------- + +Write draggable rectangle class that is initialized with a +:class:`~matplotlib.patches.Rectangle` instance but will move its x,y +location when dragged. Hint: you will need to store the orginal +``xy`` location of the rectangle which is stored as rect.xy and +connect to the press, motion and release mouse events. When the mouse +is pressed, check to see if the click occurs over your rectangle (see +:meth:`matplotlib.patches.Rectangle.contains`) and if it does, store +the rectangle xy and the location of the mouse click in data coords. +In the motion event callback, compute the deltax and deltay of the +mouse movement, and add those deltas to the origin of the rectangle +you stored. The redraw the figure. On the button release event, just +reset all the button press data you stored as None. + +Here is the solution:: + + import numpy as np + import matplotlib.pyplot as plt + + class DraggableRectangle: + def __init__(self, rect): + self.rect = rect + self.press = None + + def connect(self): + 'connect to all the events we need' + self.cidpress = self.rect.figure.canvas.mpl_connect( + 'button_press_event', self.on_press) + self.cidrelease = self.rect.figure.canvas.mpl_connect( + 'button_release_event', self.on_release) + self.cidmotion = self.rect.figure.canvas.mpl_connect( + 'motion_notify_event', self.on_motion) + + def on_press(self, event): + 'on button press we will see if the mouse is over us and store some data' + if event.inaxes != self.rect.axes: return + + contains, attrd = self.rect.contains(event) + if not contains: return + print 'event contains', self.rect.xy + x0, y0 = self.rect.xy + self.press = x0, y0, event.xdata, event.ydata + + def on_motion(self, event): + 'on motion we will move the rect if the mouse is over us' + if self.press is None: return + if event.inaxes != self.rect.axes: return + x0, y0, xpress, ypress = self.press + dx = event.xdata - xpress + dy = event.ydata - ypress + #print 'x0=%f, xpress=%f, event.xdata=%f, dx=%f, x0+dx=%f'%(x0, xpress, event.xdata, dx, x0+dx) + self.rect.set_x(x0+dx) + self.rect.set_y(y0+dy) + + self.rect.figure.canvas.draw() + + + def on_release(self, event): + 'on release we reset the press data' + self.press = None + self.rect.figure.canvas.draw() + + def disconnect(self): + 'disconnect all the stored connection ids' + self.rect.figure.canvas.mpl_disconnect(self.cidpress) + self.rect.figure.canvas.mpl_disconnect(self.cidrelease) + self.rect.figure.canvas.mpl_disconnect(self.cidmotion) + + fig = plt.figure() + ax = fig.add_subplot(111) + rects = ax.bar(range(10), 20*np.random.rand(10)) + drs = [] + for rect in rects: + dr = DraggableRectangle(rect) + dr.connect() + drs.append(dr) + plt.show() + + +**Extra credit**: use the animation blit techniques discussed in the +`animations recipe +<http://www.scipy.org/Cookbook/Matplotlib/Animations>`_ to make the +animated drawing faster and smoother. + +Extra credit solution:: + + # draggable rectangle with the animation blit techniques; see + # http://www.scipy.org/Cookbook/Matplotlib/Animations + import numpy as np + import matplotlib.pyplot as plt + + class DraggableRectangle: + lock = None # only one can be animated at a time + def __init__(self, rect): + self.rect = rect + self.press = None + self.background = None + + def connect(self): + 'connect to all the events we need' + self.cidpress = self.rect.figure.canvas.mpl_connect( + 'button_press_event', self.on_press) + self.cidrelease = self.rect.figure.canvas.mpl_connect( + 'button_release_event', self.on_release) + self.cidmotion = self.rect.figure.canvas.mpl_connect( + 'motion_notify_event', self.on_motion) + + def on_press(self, event): + 'on button press we will see if the mouse is over us and store some data' + if event.inaxes != self.rect.axes: return + if DraggableRectangle.lock is not None: return + contains, attrd = self.rect.contains(event) + if not contains: return + print 'event contains', self.rect.xy + x0, y0 = self.rect.xy + self.press = x0, y0, event.xdata, event.ydata + DraggableRectangle.lock = self + + # draw everything but the selected rectangle and store the pixel buffer + canvas = self.rect.figure.canvas + axes = self.rect.axes + self.rect.set_animated(True) + canvas.draw() + self.background = canvas.copy_from_bbox(self.rect.axes.bbox) + + # now redraw just the rectangle + axes.draw_artist(self.rect) + + # and blit just the redrawn area + canvas.blit(axes.bbox) + + def on_motion(self, event): + 'on motion we will move the rect if the mouse is over us' + if DraggableRectangle.lock is not self: + return + if event.inaxes != self.rect.axes: return + x0, y0, xpress, ypress = self.press + dx = event.xdata - xpress + dy = event.ydata - ypress + self.rect.set_x(x0+dx) + self.rect.set_y(y0+dy) + + canvas = self.rect.figure.canvas + axes = self.rect.axes + # restore the background region + canvas.restore_region(self.background) + + # redraw just the current rectangle + axes.draw_artist(self.rect) + + # blit just the redrawn area + canvas.blit(axes.bbox) + + def on_release(self, event): + 'on release we reset the press data' + if DraggableRectangle.lock is not self: + return + + self.press = None + DraggableRectangle.lock = None + + # turn off the rect animation property and reset the background + self.rect.set_animated(False) + self.background = None + + # redraw the full figure + self.rect.figure.canvas.draw() + + def disconnect(self): + 'disconnect all the stored connection ids' + self.rect.figure.canvas.mpl_disconnect(self.cidpress) + self.rect.figure.canvas.mpl_disconnect(self.cidrelease) + self.rect.figure.canvas.mpl_disconnect(self.cidmotion) + + fig = plt.figure() + ax = fig.add_subplot(111) + rects = ax.bar(range(10), 20*np.random.rand(10)) + drs = [] + for rect in rects: + dr = DraggableRectangle(rect) + dr.connect() + drs.append(dr) + + plt.show() + + +.. _enter-leave-events: + +Mouse enter and leave +====================== + +If you want to be notified when the mouse enters or leaves a figure or +axes, you can connect to the figure/axes enter/leave events. Here is +a simple example that changes the colors of the axes and figure +background that the mouse is over:: + + """ + Illustrate the figure and axes enter and leave events by changing the + frame colors on enter and leave + """ + import matplotlib.pyplot as plt + + def enter_axes(event): + print 'enter_axes', event.inaxes + event.inaxes.patch.set_facecolor('yellow') + event.canvas.draw() + + def leave_axes(event): + print 'leave_axes', event.inaxes + event.inaxes.patch.set_facecolor('white') + event.canvas.draw() + + def enter_figure(event): + print 'enter_figure', event.canvas.figure + event.canvas.figure.patch.set_facecolor('red') + event.canvas.draw() + + def leave_figure(event): + print 'leave_figure', event.canvas.figure + event.canvas.figure.patch.set_facecolor('grey') + event.canvas.draw() + + fig1 = plt.figure() + fig1.suptitle('mouse hover over figure or axes to trigger events') + ax1 = fig1.add_subplot(211) + ax2 = fig1.add_subplot(212) + + fig1.canvas.mpl_connect('figure_enter_event', enter_figure) + fig1.canvas.mpl_connect('figure_leave_event', leave_figure) + fig1.canvas.mpl_connect('axes_enter_event', enter_axes) + fig1.canvas.mpl_connect('axes_leave_event', leave_axes) + + fig2 = plt.figure() + fig2.suptitle('mouse hover over figure or axes to trigger events') + ax1 = fig2.add_subplot(211) + ax2 = fig2.add_subplot(212) + + fig2.canvas.mpl_connect('figure_enter_event', enter_figure) + fig2.canvas.mpl_connect('figure_leave_event', leave_figure) + fig2.canvas.mpl_connect('axes_enter_event', enter_axes) + fig2.canvas.mpl_connect('axes_leave_event', leave_axes) + + plt.show() + + + +.. _object-picking: + +Object picking +============== + +You can enable picking by setting the ``picker`` property of an +:class:`~matplotlib.artist.Artist` (eg a matplotlib +:class:`~matplotlib.lines.Line2D`, :class:`~matplotlib.text.Text`, +:class:`~matplotlib.patches.Patch`, :class:`~matplotlib.patches.Polygon`, +:class:`~matplotlib.patches.AxesImage`, etc...) + +There are a variety of meanings of the ``picker`` property: + + ``None`` + picking is disabled for this artist (default) + + ``boolean`` + if True then picking will be enabled and the artist will fire a + pick event if the mouse event is over the artist + + ``float`` + if picker is a number it is interpreted as an epsilon tolerance in + points and the the artist will fire off an event if its data is + within epsilon of the mouse event. For some artists like lines + and patch collections, the artist may provide additional data to + the pick event that is generated, eg the indices of the data + within epsilon of the pick event. + + ``function`` + if picker is callable, it is a user supplied function which + determines whether the artist is hit by the mouse event. The + signature is ``hit, props = picker(artist, mouseevent)`` to + determine the hit test. If the mouse event is over the artist, + return ``hit=True`` and props is a dictionary of properties you + want added to the :class:`~matplotlib.backend_bases.PickEvent` + attributes + + +After you have enabled an artist for picking by setting the ``picker`` +property, you need to connect to the figure canvas pick_event to get +pick callbacks on mouse press events. Eg:: + + def pick_handler(event): + mouseevent = event.mouseevent + artist = event.artist + # now do something with this... + + +The :class:`~matplotlib.backend_bases.PickEvent` which is passed to +your callback is always fired with two attributes: + + ``mouseevent`` the mouse event that generate the pick event. The + mouse event in turn has attributes like ``x`` and ``y`` (the + coords in display space, eg pixels from left, bottom) and xdata, + ydata (the coords in data space). Additionally, you can get + information about which buttons were pressed, which keys were + pressed, which :class:`~matplotlib.axes.Axes` the mouse is over, + etc. See :class:`matplotlib.backend_bases.MouseEvent` for + details. + + ``artist`` + the :class:`~matplotlib.artist.Artist` that generated the pick + event. + +Additionally, certain artists like :class:`~matplotlib.lines.Line2D` +and :class:`~matplotlib.collections.PatchCollection` may attach +additional meta data like the indices into the data that meet the +picker criteria (eg all the points in the line that are within the +specified epsilon tolerance) + +Simple picking example +---------------------- + +In the example below, we set the line picker property to a scalar, so +it represents a tolerance in points (72 points per inch). The onpick +callback function will be called when the pick event it within the +tolerance distance from the line, and has the indices of the data +vertices that are within the pick distance tolerance. Our onpick +callback function simply prints the data that are under the pick +location. Different matplotlib Artists can attach different data to +the PickEvent. For example, ``Line2D`` attaches the ind property, +which are the indices into the line data under the pick point. See +:meth:`~matplotlib.lines.Line2D.pick` for details on the ``PickEvent`` +properties of the line. Here is the code:: + + import numpy as np + import matplotlib.pyplot as plt + + fig = plt.figure() + ax = fig.add_subplot(111) + ax.set_title('click on points') + + line, = ax.plot(np.random.rand(100), 'o', picker=5) # 5 points tolerance + + def onpick(event): + thisline = event.artist + xdata = thisline.get_xdata() + ydata = thisline.get_ydata() + ind = event.ind + print 'onpick points:', zip(xdata[ind], ydata[ind]) + + fig.canvas.mpl_connect('pick_event', onpick) + + plt.show() + + +Picking exercise +---------------- + +Create a data set of 100 arrays of 1000 Gaussian random numbers and +compute the sample mean and standard deviation of each of them (hint: +numpy arrays have a mean and std method) and make a xy marker plot of +the 100 means vs the 100 standard deviations. Connect the line +created by the plot command to the pick event, and plot the original +time series of the data that generated the clicked on points. If more +than one point is within the tolerance of the clicked on point, you +can use multiple subplots to plot the multiple time series. + +Exercise solution:: + + """ + compute the mean and stddev of 100 data sets and plot mean vs stddev. + When you click on one of the mu, sigma points, plot the raw data from + the dataset that generated the mean and stddev + """ + import numpy as np + import matplotlib.pyplot as plt + + X = np.random.rand(100, 1000) + xs = np.mean(X, axis=1) + ys = np.std(X, axis=1) + + fig = plt.figure() + ax = fig.add_subplot(111) + ax.set_title('click on point to plot time series') + line, = ax.plot(xs, ys, 'o', picker=5) # 5 points tolerance + + + def onpick(event): + + if event.artist!=line: return True + + N = len(event.ind) + if not N: return True + + + figi = plt.figure() + for subplotnum, dataind in enumerate(event.ind): + ax = figi.add_subplot(N,1,subplotnum+1) + ax.plot(X[dataind]) + ax.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f'%(xs[dataind], ys[dataind]), + transform=ax.transAxes, va='top') + ax.set_ylim(-0.5, 1.5) + figi.show() + return True + + fig.canvas.mpl_connect('pick_event', onpick) + + plt.show() Modified: trunk/matplotlib/doc/users/pyplot_tutorial.rst =================================================================== --- trunk/matplotlib/doc/users/pyplot_tutorial.rst 2009年08月08日 06:07:06 UTC (rev 7424) +++ trunk/matplotlib/doc/users/pyplot_tutorial.rst 2009年08月08日 06:24:00 UTC (rev 7425) @@ -74,7 +74,7 @@ one line so it is a list of length 1. I use tuple unpacking in the ``line, = plot(x, y, 'o')`` to get the first element of the list:: - line, = plt.plot(x, y, 'o') + line, = plt.plot(x, y, '-') line.set_antialiased(False) # turn off antialising * Use the :func:`~matplotlib.pyplot.setp` command. The example below @@ -156,7 +156,7 @@ :func:`~matplotlib.pyplot.gcf` returns the current figure (:class:`matplotlib.figure.Figure` instance). Normally, you don't have to worry about this, because it is all taken care of behind the -scenes. Below is an script to create two subplots. +scenes. Below is a script to create two subplots. .. plot:: pyplots/pyplot_two_subplots.py :include-source: @@ -165,18 +165,16 @@ ``figure(1)`` will be created by default, just as a ``subplot(111)`` will be created by default if you don't manually specify an axes. The :func:`~matplotlib.pyplot.subplot` command specifies ``numrows, -numcols, fignum`` where ``fignum`` ranges from 1 to -``numrows*numcols``. The commas in the ``subplot command are optional + numcols, fignum`` where ``fignum`` ranges from 1 to +``numrows*numcols``. The commas in the ``subplot`` command are optional if ``numr... [truncated message content]
Revision: 7424 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7424&view=rev Author: efiring Date: 2009年08月08日 06:07:06 +0000 (2009年8月08日) Log Message: ----------- Restore default colormap behavior: no color (alpha = 0) for masked data Modified Paths: -------------- branches/v0_99_maint/lib/matplotlib/colors.py Modified: branches/v0_99_maint/lib/matplotlib/colors.py =================================================================== --- branches/v0_99_maint/lib/matplotlib/colors.py 2009年08月08日 02:06:56 UTC (rev 7423) +++ branches/v0_99_maint/lib/matplotlib/colors.py 2009年08月08日 06:07:06 UTC (rev 7424) @@ -488,7 +488,10 @@ if not self._isinit: self._init() alpha = min(alpha, 1.0) # alpha must be between 0 and 1 alpha = max(alpha, 0.0) - self._lut[:,-1] = alpha + self._lut[:-1,-1] = alpha # Don't assign global alpha to i_bad; + # it would defeat the purpose of the + # default behavior, which is to not + # show anything where data are missing. mask_bad = None if not cbook.iterable(X): vtype = 'scalar' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 7423 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7423&view=rev Author: leejjoon Date: 2009年08月08日 02:06:56 +0000 (2009年8月08日) Log Message: ----------- BboxImage implemented and two examples added. Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/image.py Added Paths: ----------- trunk/matplotlib/examples/pylab_examples/demo_bboximage.py trunk/matplotlib/examples/pylab_examples/demo_ribbon_box.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009年08月08日 01:46:44 UTC (rev 7422) +++ trunk/matplotlib/CHANGELOG 2009年08月08日 02:06:56 UTC (rev 7423) @@ -1,3 +1,6 @@ +2009年08月07日 BboxImage implemented. Two examples, demo_bboximage.py and + demo_ribbon_box.py added. - JJL + 2009年08月07日 In an effort to simplify the backend API, all clipping rectangles and paths are now passed in using GraphicsContext objects, even on collections and images. Therefore: Added: trunk/matplotlib/examples/pylab_examples/demo_bboximage.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/demo_bboximage.py (rev 0) +++ trunk/matplotlib/examples/pylab_examples/demo_bboximage.py 2009年08月08日 02:06:56 UTC (rev 7423) @@ -0,0 +1,62 @@ +import matplotlib.pyplot as plt +import numpy as np +from matplotlib.image import BboxImage +from matplotlib.transforms import Bbox, TransformedBbox + +if __name__ == "__main__": + + fig = plt.figure(1) + ax = plt.subplot(121) + + txt = ax.text(0.5, 0.5, "test", size=30, ha="center", color="w") + kwargs = dict() + + bbox_image = BboxImage(txt.get_window_extent, + norm = None, + origin=None, + clip_on=False, + **kwargs + ) + a = np.arange(256).reshape(1,256)/256. + bbox_image.set_data(a) + ax.add_artist(bbox_image) + + + ax = plt.subplot(122) + a = np.linspace(0, 1, 256).reshape(1,-1) + a = np.vstack((a,a)) + + maps = sorted(m for m in plt.cm.datad if not m.endswith("_r")) + #nmaps = len(maps) + 1 + + #fig.subplots_adjust(top=0.99, bottom=0.01, left=0.2, right=0.99) + + ncol = 2 + nrow = len(maps)//ncol + 1 + + xpad_fraction = 0.3 + dx = 1./(ncol + xpad_fraction*(ncol-1)) + + ypad_fraction = 0.3 + dy = 1./(nrow + ypad_fraction*(nrow-1)) + + for i,m in enumerate(maps): + ix, iy = divmod(i, nrow) + #plt.figimage(a, 10, i*10, cmap=plt.get_cmap(m), origin='lower') + bbox0 = Bbox.from_bounds(ix*dx*(1+xpad_fraction), + 1.-iy*dy*(1+ypad_fraction)-dy, + dx, dy) + bbox = TransformedBbox(bbox0, ax.transAxes) + + bbox_image = BboxImage(bbox, + cmap = plt.get_cmap(m), + norm = None, + origin=None, + **kwargs + ) + + bbox_image.set_data(a) + ax.add_artist(bbox_image) + + plt.draw() + plt.show() Added: trunk/matplotlib/examples/pylab_examples/demo_ribbon_box.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/demo_ribbon_box.py (rev 0) +++ trunk/matplotlib/examples/pylab_examples/demo_ribbon_box.py 2009年08月08日 02:06:56 UTC (rev 7423) @@ -0,0 +1,140 @@ +import matplotlib.pyplot as plt +import numpy as np +from matplotlib.image import BboxImage + +from matplotlib._png import read_png +import matplotlib.colors +from matplotlib.cbook import get_sample_data + +class RibbonBox(object): + + original_image = read_png(get_sample_data("Minduka_Present_Blue_Pack.png", + asfileobj=False)) + cut_location = 70 + b_and_h = original_image[:,:,2] + color = original_image[:,:,2] - original_image[:,:,0] + alpha = original_image[:,:,3] + nx = original_image.shape[1] + + def __init__(self, color): + rgb = matplotlib.colors.colorConverter.to_rgb(color) + + im = np.empty(self.original_image.shape, + self.original_image.dtype) + + + im[:,:,:3] = self.b_and_h[:,:,np.newaxis] + im[:,:,:3] -= self.color[:,:,np.newaxis]*(1.-np.array(rgb)) + im[:,:,3] = self.alpha + + self.im = im + + + def get_stretched_image(self, stretch_factor): + stretch_factor = max(stretch_factor, 1) + ny, nx, nch = self.im.shape + ny2 = int(ny*stretch_factor) + + stretched_image = np.empty((ny2, nx, nch), + self.im.dtype) + cut = self.im[self.cut_location,:,:] + stretched_image[:,:,:] = cut + stretched_image[:self.cut_location,:,:] = \ + self.im[:self.cut_location,:,:] + stretched_image[-(ny-self.cut_location):,:,:] = \ + self.im[-(ny-self.cut_location):,:,:] + + self._cached_im = stretched_image + return stretched_image + + + +class RibbonBoxImage(BboxImage): + zorder = 1 + + def __init__(self, bbox, color, + cmap = None, + norm = None, + interpolation=None, + origin=None, + filternorm=1, + filterrad=4.0, + resample = False, + **kwargs + ): + + BboxImage.__init__(self, bbox, + cmap = None, + norm = None, + interpolation=None, + origin=None, + filternorm=1, + filterrad=4.0, + resample = False, + **kwargs + ) + + self._ribbonbox = RibbonBox(color) + self._cached_ny = None + + + def draw(self, renderer, *args, **kwargs): + + bbox = self.get_window_extent(renderer) + stretch_factor = bbox.height / bbox.width + + ny = int(stretch_factor*self._ribbonbox.nx) + if self._cached_ny != ny: + arr = self._ribbonbox.get_stretched_image(stretch_factor) + self.set_array(arr) + self._cached_ny = ny + + BboxImage.draw(self, renderer, *args, **kwargs) + + +if 1: + from matplotlib.transforms import Bbox, TransformedBbox + from matplotlib.ticker import ScalarFormatter + + fig = plt.gcf() + fig.clf() + ax = plt.subplot(111) + + years = np.arange(2004, 2009) + box_colors = [(0.8, 0.2, 0.2), + (0.2, 0.8, 0.2), + (0.2, 0.2, 0.8), + (0.7, 0.5, 0.8), + (0.3, 0.8, 0.7), + ] + heights = np.random.random(years.shape) * 7000 + 3000 + + fmt = ScalarFormatter(useOffset=False) + ax.xaxis.set_major_formatter(fmt) + + for year, h, bc in zip(years, heights, box_colors): + bbox0 = Bbox.from_extents(year-0.4, 0., year+0.4, h) + bbox = TransformedBbox(bbox0, ax.transData) + rb_patch = RibbonBoxImage(bbox, bc) + + ax.add_artist(rb_patch) + + ax.annotate(r"%d" % (int(h/100.)*100), + (year, h), va="bottom", ha="center") + + patch_gradient = BboxImage(ax.bbox, + interpolation="bicubic", + zorder=0.1, + ) + gradient = np.zeros((2, 2, 4), dtype=np.float) + gradient[:,:,:3] = [1, 1, 0.] + gradient[:,:,3] = [[0.1, 0.3],[0.3, 0.5]] # alpha channel + patch_gradient.set_array(gradient) + ax.add_artist(patch_gradient) + + + ax.set_xlim(years[0]-0.5, years[-1]+0.5) + ax.set_ylim(0, 10000) + + plt.show() + Modified: trunk/matplotlib/lib/matplotlib/image.py =================================================================== --- trunk/matplotlib/lib/matplotlib/image.py 2009年08月08日 01:46:44 UTC (rev 7422) +++ trunk/matplotlib/lib/matplotlib/image.py 2009年08月08日 02:06:56 UTC (rev 7423) @@ -24,6 +24,8 @@ # the image namespace: from matplotlib._image import * +from matplotlib.transforms import BboxBase + class AxesImage(martist.Artist, cm.ScalarMappable): zorder = 1 # map interpolation strings to module constants @@ -744,6 +746,149 @@ rows, cols, buffer = im.as_rgba_str() _png.write_png(buffer, cols, rows, fname) + +class BboxImage(AxesImage): + """ + The Image class whose size is determined by the given bbox. + """ + zorder = 1 + def __init__(self, bbox, + cmap = None, + norm = None, + interpolation=None, + origin=None, + filternorm=1, + filterrad=4.0, + resample = False, + **kwargs + ): + + """ + cmap is a colors.Colormap instance + norm is a colors.Normalize instance to map luminance to 0-1 + + kwargs are an optional list of Artist keyword args + """ + + AxesImage.__init__(self, ax=None, + cmap = cmap, + norm = norm, + interpolation=interpolation, + origin=origin, + filternorm=filternorm, + filterrad=filterrad, + resample = resample, + **kwargs + ) + + self.bbox = bbox + + def get_window_extent(self, renderer=None): + if renderer is None: + renderer = self.get_figure()._cachedRenderer + + if isinstance(self.bbox, BboxBase): + return self.bbox + elif callable(self.bbox): + return self.bbox(renderer) + else: + raise ValueError("unknown type of bbox") + + + def contains(self, mouseevent): + """Test whether the mouse event occured within the image. + """ + + if callable(self._contains): return self._contains(self,mouseevent) + + if not self.get_visible():# or self.get_figure()._renderer is None: + return False,{} + + x, y = mouseevent.x, mouseevent.y + inside = self.get_window_extent().contains(x, y) + + return inside,{} + + def get_size(self): + 'Get the numrows, numcols of the input image' + if self._A is None: + raise RuntimeError('You must first set the image array') + + return self._A.shape[:2] + + def make_image(self, renderer, magnification=1.0): + if self._A is None: + raise RuntimeError('You must first set the image array or the image attribute') + + if self._imcache is None: + if self._A.dtype == np.uint8 and len(self._A.shape) == 3: + im = _image.frombyte(self._A, 0) + im.is_grayscale = False + else: + if self._rgbacache is None: + x = self.to_rgba(self._A, self._alpha) + self._rgbacache = x + else: + x = self._rgbacache + im = _image.fromarray(x, 0) + if len(self._A.shape) == 2: + im.is_grayscale = self.cmap.is_gray() + else: + im.is_grayscale = False + self._imcache = im + + if self.origin=='upper': + im.flipud_in() + else: + im = self._imcache + + if 0: + fc = self.axes.patch.get_facecolor() + bg = mcolors.colorConverter.to_rgba(fc, 0) + im.set_bg( *bg) + + # image input dimensions + im.reset_matrix() + + im.set_interpolation(self._interpd[self._interpolation]) + + im.set_resample(self._resample) + + l, b, r, t = self.get_window_extent(renderer).extents #bbox.extents + widthDisplay = (round(r) + 0.5) - (round(l) - 0.5) + heightDisplay = (round(t) + 0.5) - (round(b) - 0.5) + widthDisplay *= magnification + heightDisplay *= magnification + #im.apply_translation(tx, ty) + + numrows, numcols = self._A.shape[:2] + + # resize viewport to display + rx = widthDisplay / numcols + ry = heightDisplay / numrows + #im.apply_scaling(rx*sx, ry*sy) + im.apply_scaling(rx, ry) + #im.resize(int(widthDisplay+0.5), int(heightDisplay+0.5), + # norm=self._filternorm, radius=self._filterrad) + im.resize(int(widthDisplay), int(heightDisplay), + norm=self._filternorm, radius=self._filterrad) + return im + + + @allow_rasterization + def draw(self, renderer, *args, **kwargs): + if not self.get_visible(): return + # todo: we should be able to do some cacheing here + image_mag = renderer.get_image_magnification() + im = self.make_image(renderer, image_mag) + l, b, r, t = self.get_window_extent(renderer).extents + gc = renderer.new_gc() + self._set_gc_clip(gc) + #gc.set_clip_path(self.get_clip_path()) + renderer.draw_image(gc, round(l), round(b), im) + + + def imread(fname): """ Return image file in *fname* as :class:`numpy.array`. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 7422 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7422&view=rev Author: efiring Date: 2009年08月08日 01:46:44 +0000 (2009年8月08日) Log Message: ----------- Convert slit paths to compound paths inside cntr.c. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/contour.py trunk/matplotlib/src/cntr.c Modified: trunk/matplotlib/lib/matplotlib/contour.py =================================================================== --- trunk/matplotlib/lib/matplotlib/contour.py 2009年08月08日 01:40:31 UTC (rev 7421) +++ trunk/matplotlib/lib/matplotlib/contour.py 2009年08月08日 01:46:44 UTC (rev 7422) @@ -539,7 +539,6 @@ """ self.ax = ax - self.noslit = kwargs.get('noslit', False) # **Temporary** self.levels = kwargs.get('levels', None) self.filled = kwargs.get('filled', False) self.linewidths = kwargs.get('linewidths', None) @@ -599,8 +598,6 @@ self.collections = cbook.silent_list('collections.PathCollection') else: self.collections = cbook.silent_list('collections.LineCollection') - self.segs = [] - self.kinds = [] # label lists must be initialized here self.labelTexts = [] self.labelCValues = [] @@ -629,8 +626,6 @@ alpha=self.alpha) self.ax.add_collection(col) self.collections.append(col) - self.segs.append(segs) - self.kinds.append(kinds) else: tlinewidths = self._process_linewidths() self.tlinewidths = tlinewidths @@ -639,7 +634,7 @@ nlist = C.trace(level) nseg = len(nlist)//2 segs = nlist[:nseg] - kinds = nlist[nseg:] + #kinds = nlist[nseg:] col = collections.LineCollection(segs, linewidths = width, linestyle = lstyle, @@ -648,24 +643,16 @@ col.set_label('_nolegend_') self.ax.add_collection(col, False) self.collections.append(col) - self.segs.append(segs) - self.kinds.append(kinds) self.changed() # set the colors def _make_paths(self, segs, kinds): paths = [] for seg, kind in zip(segs, kinds): - codes = np.zeros(kind.shape, dtype=mpath.Path.code_type) - codes.fill(mpath.Path.LINETO) - codes[0] = mpath.Path.MOVETO - # points that begin a slit or are in it: - # use moveto for any point *following* such a point - if self.noslit: - in_slit = kind[:-1] >= _cntr._slitkind - codes[1:][in_slit] = mpath.Path.MOVETO - paths.append(mpath.Path(seg, codes)) + paths.append(mpath.Path(seg, codes=kind)) return paths + + def changed(self): tcolors = [ (tuple(rgba),) for rgba in self.to_rgba(self.cvalues, alpha=self.alpha)] Modified: trunk/matplotlib/src/cntr.c =================================================================== --- trunk/matplotlib/src/cntr.c 2009年08月08日 01:40:31 UTC (rev 7421) +++ trunk/matplotlib/src/cntr.c 2009年08月08日 01:46:44 UTC (rev 7422) @@ -1318,9 +1318,134 @@ site = NULL; } +#define MOVETO 1 +#define LINETO 2 -/* Build a list of XY 2-D arrays, shape (N,2), to which a list of K arrays - is concatenated. */ +int reorder(double *xpp, double *ypp, short *kpp, + double *xy, unsigned char *c, int npts) +{ + int *i0; + int *i1; + int *subp=NULL; /* initialized to suppress warning */ + int isp, nsp; + int iseg, nsegs; + int isegplus; + int i; + int k; + int started; + int maxnsegs = npts/2 + 1; + + /* allocate maximum possible size--gross overkill */ + i0 = malloc(maxnsegs * sizeof(int)); + i1 = malloc(maxnsegs * sizeof(int)); + + /* Find the segments. */ + iseg = 0; + started = 0; + for (i=0; i<npts; i++) + { + if (started) + { + if ((kpp[i] >= kind_slit_up) || (i == npts-1)) + { + i1[iseg] = i; + started = 0; + iseg++; + if (iseg == maxnsegs) + { + k = -1; + goto ending; + } + } + } + else if ((kpp[i] < kind_slit_up) && (i < npts-1)) + { + i0[iseg] = i; + started = 1; + } + } + + nsegs = iseg; + + + /* Find the subpaths as sets of connected segments. */ + + subp = malloc(nsegs * sizeof(int)); + for (i=0; i<nsegs; i++) subp[i] = -1; + + nsp = 0; + for (iseg=0; iseg<nsegs; iseg++) + { + /* For each segment, if it is not closed, look ahead for + the next connected segment. + */ + double xend, yend; + xend = xpp[i1[iseg]]; + yend = ypp[i1[iseg]]; + if (subp[iseg] >= 0) continue; + subp[iseg] = nsp; + nsp++; + if (iseg == nsegs-1) continue; + for (isegplus = iseg+1; isegplus < nsegs; isegplus++) + { + if (subp[isegplus] >= 0) continue; + + if (xend == xpp[i0[isegplus]] && yend == ypp[i0[isegplus]]) + { + subp[isegplus] = subp[iseg]; + xend = xpp[i1[isegplus]]; + yend = ypp[i1[isegplus]]; + } + + } + } + + /* Generate the verts and codes from the subpaths. */ + k = 0; + for (isp=0; isp<nsp; isp++) + { + int first = 1; + for (iseg=0; iseg<nsegs; iseg++) + { + int istart, iend; + if (subp[iseg] != isp) continue; + iend = i1[iseg]; + if (first) + { + istart = i0[iseg]; + } + else + { + istart = i0[iseg]+1; /* skip duplicate */ + } + for (i=istart; i<=iend; i++) + { + xy[2*k] = xpp[i]; + xy[2*k+1] = ypp[i]; + if (first) c[k] = MOVETO; + else c[k] = LINETO; + first = 0; + k++; + if (k > npts) /* should never happen */ + { + k = -1; + goto ending; + } + } + } + } + + ending: + free(i0); + free(i1); + free(subp); + + return k; +} + +/* Build a list of XY 2-D arrays, shape (N,2), to which a list of path + code arrays is concatenated. +*/ static PyObject * build_cntr_list_v2(long *np, double *xp, double *yp, short *kp, int nparts, long ntotal) @@ -1331,6 +1456,73 @@ npy_intp dims[2]; npy_intp kdims[1]; int i; + long k; + + PyArray_Dims newshape; + + all_contours = PyList_New(nparts*2); + + for (i=0, k=0; i < nparts; k+= np[i], i++) + { + double *xpp = xp+k; + double *ypp = yp+k; + short *kpp = kp+k; + int n; + + + dims[0] = np[i]; + dims[1] = 2; + kdims[0] = np[i]; + xyv = (PyArrayObject *) PyArray_SimpleNew(2, dims, PyArray_DOUBLE); + if (xyv == NULL) goto error; + kv = (PyArrayObject *) PyArray_SimpleNew(1, kdims, PyArray_UBYTE); + if (kv == NULL) goto error; + + n = reorder(xpp, ypp, kpp, + (double *) xyv->data, + (unsigned char *) kv->data, + np[i]); + if (n == -1) goto error; + newshape.len = 2; + dims[0] = n; + newshape.ptr = dims; + if (PyArray_Resize(xyv, &newshape, 1, NPY_CORDER) == NULL) goto error; + + newshape.len = 1; /* ptr, dims can stay the same */ + if (PyArray_Resize(kv, &newshape, 1, NPY_CORDER) == NULL) goto error; + + + if (PyList_SetItem(all_contours, i, (PyObject *)xyv)) goto error; + if (PyList_SetItem(all_contours, nparts+i, + (PyObject *)kv)) goto error; + } + return all_contours; + + error: + Py_XDECREF(xyv); + Py_XDECREF(kv); + Py_XDECREF(all_contours); + return NULL; +} + +#if 0 /* preprocess this out when we are not using it. */ +/* Build a list of XY 2-D arrays, shape (N,2), to which a list of K arrays + is concatenated. + This is kept in the code in case we need to switch back to it, + or in case we need it for investigating the infamous internal + masked region bug. +*/ + +static PyObject * +__build_cntr_list_v2(long *np, double *xp, double *yp, short *kp, + int nparts, long ntotal) +{ + PyObject *all_contours; + PyArrayObject *xyv; + PyArrayObject *kv; + npy_intp dims[2]; + npy_intp kdims[1]; + int i; long j, k; all_contours = PyList_New(nparts*2); @@ -1364,6 +1556,7 @@ return NULL; } +#endif /* preprocessing out the old version for now */ /* cntr_trace is called once per contour level or level pair. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 7421 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7421&view=rev Author: leejjoon Date: 2009年08月08日 01:40:31 +0000 (2009年8月08日) Log Message: ----------- add ribbon box image Added Paths: ----------- trunk/sample_data/Minduka_Present_Blue_Pack.png Added: trunk/sample_data/Minduka_Present_Blue_Pack.png =================================================================== (Binary files differ) Property changes on: trunk/sample_data/Minduka_Present_Blue_Pack.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.