From: <evi...@us...> - 2009-08-12 23:30:23
|
Revision: 7479 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7479&view=rev Author: evilguru Date: 2009-08-12 23:30:13 +0000 (Wed, 12 Aug 2009) Log Message: ----------- Backport recent changes in trunk to the mathtex branch. Modified Paths: -------------- branches/mathtex/CHANGELOG branches/mathtex/boilerplate.py branches/mathtex/doc/_templates/index.html branches/mathtex/doc/_templates/indexsidebar.html branches/mathtex/doc/api/api_changes.rst branches/mathtex/doc/api/spine_api.rst branches/mathtex/doc/devel/coding_guide.rst branches/mathtex/doc/faq/installing_faq.rst branches/mathtex/doc/pyplots/plotmap.py branches/mathtex/doc/users/annotations.rst branches/mathtex/doc/users/artists.rst branches/mathtex/doc/users/credits.rst branches/mathtex/doc/users/event_handling.rst branches/mathtex/doc/users/installing.rst branches/mathtex/doc/users/plotting.rst branches/mathtex/doc/users/pyplot_tutorial.rst branches/mathtex/doc/users/screenshots.rst branches/mathtex/doc/users/whats_new.rst branches/mathtex/examples/api/date_demo.py branches/mathtex/examples/api/date_index_formatter.py branches/mathtex/examples/api/watermark_image.py branches/mathtex/examples/axes_grid/demo_axes_divider.py branches/mathtex/examples/axes_grid/demo_axes_grid.py branches/mathtex/examples/axes_grid/inset_locator_demo2.py branches/mathtex/examples/axes_grid/simple_axesgrid2.py branches/mathtex/examples/axes_grid/simple_rgb.py branches/mathtex/examples/misc/rec_groupby_demo.py branches/mathtex/examples/misc/rec_join_demo.py branches/mathtex/examples/mplot3d/2dcollections3d_demo.py branches/mathtex/examples/mplot3d/bars3d_demo.py branches/mathtex/examples/mplot3d/contour3d_demo.py branches/mathtex/examples/mplot3d/contour3d_demo2.py branches/mathtex/examples/mplot3d/contourf3d_demo.py branches/mathtex/examples/mplot3d/hist3d_demo.py branches/mathtex/examples/mplot3d/lines3d_demo.py branches/mathtex/examples/mplot3d/polys3d_demo.py branches/mathtex/examples/mplot3d/scatter3d_demo.py branches/mathtex/examples/mplot3d/surface3d_demo.py branches/mathtex/examples/mplot3d/surface3d_demo2.py branches/mathtex/examples/mplot3d/text3d_demo.py branches/mathtex/examples/mplot3d/wire3d_demo.py branches/mathtex/examples/pylab_examples/centered_ticklabels.py branches/mathtex/examples/pylab_examples/contourf_demo.py branches/mathtex/examples/pylab_examples/data_helper.py branches/mathtex/examples/pylab_examples/date_index_formatter.py branches/mathtex/examples/pylab_examples/image_demo2.py branches/mathtex/examples/pylab_examples/image_demo3.py branches/mathtex/examples/pylab_examples/load_converter.py branches/mathtex/examples/pylab_examples/loadrec.py branches/mathtex/examples/pylab_examples/logo.py branches/mathtex/examples/pylab_examples/mri_demo.py branches/mathtex/examples/pylab_examples/mri_with_eeg.py branches/mathtex/examples/pylab_examples/plotfile_demo.py branches/mathtex/examples/pylab_examples/quadmesh_demo.py branches/mathtex/examples/pylab_examples/scatter_demo2.py branches/mathtex/examples/tests/backend_driver.py branches/mathtex/examples/user_interfaces/embedding_in_wx3.py branches/mathtex/examples/user_interfaces/rec_edit_gtk_custom.py branches/mathtex/examples/user_interfaces/rec_edit_gtk_simple.py branches/mathtex/lib/matplotlib/__init__.py branches/mathtex/lib/matplotlib/axes.py branches/mathtex/lib/matplotlib/backend_bases.py branches/mathtex/lib/matplotlib/backends/backend_agg.py branches/mathtex/lib/matplotlib/backends/backend_cairo.py branches/mathtex/lib/matplotlib/backends/backend_gdk.py branches/mathtex/lib/matplotlib/backends/backend_gtk.py branches/mathtex/lib/matplotlib/backends/backend_macosx.py branches/mathtex/lib/matplotlib/backends/backend_mixed.py branches/mathtex/lib/matplotlib/backends/backend_pdf.py branches/mathtex/lib/matplotlib/backends/backend_ps.py branches/mathtex/lib/matplotlib/backends/backend_svg.py branches/mathtex/lib/matplotlib/backends/backend_template.py branches/mathtex/lib/matplotlib/backends/backend_wx.py branches/mathtex/lib/matplotlib/bezier.py branches/mathtex/lib/matplotlib/cbook.py branches/mathtex/lib/matplotlib/collections.py branches/mathtex/lib/matplotlib/colors.py branches/mathtex/lib/matplotlib/contour.py branches/mathtex/lib/matplotlib/figure.py branches/mathtex/lib/matplotlib/font_manager.py branches/mathtex/lib/matplotlib/image.py branches/mathtex/lib/matplotlib/legend.py branches/mathtex/lib/matplotlib/mlab.py branches/mathtex/lib/matplotlib/offsetbox.py branches/mathtex/lib/matplotlib/patches.py branches/mathtex/lib/matplotlib/path.py branches/mathtex/lib/matplotlib/pylab.py branches/mathtex/lib/matplotlib/pyplot.py branches/mathtex/lib/matplotlib/texmanager.py branches/mathtex/lib/matplotlib/text.py branches/mathtex/lib/mpl_toolkits/axes_grid/anchored_artists.py branches/mathtex/lib/mpl_toolkits/axes_grid/angle_helper.py branches/mathtex/lib/mpl_toolkits/axes_grid/axes_divider.py branches/mathtex/lib/mpl_toolkits/mplot3d/art3d.py branches/mathtex/lib/mpl_toolkits/mplot3d/axes3d.py branches/mathtex/lib/mpl_toolkits/mplot3d/axis3d.py branches/mathtex/lib/mpl_toolkits/mplot3d/proj3d.py branches/mathtex/release/osx/Makefile branches/mathtex/release/osx/README.txt branches/mathtex/release/win32/Makefile branches/mathtex/setupext.py branches/mathtex/src/_backend_agg.cpp branches/mathtex/src/_backend_agg.h branches/mathtex/src/_macosx.m branches/mathtex/src/cntr.c Removed Paths: ------------- branches/mathtex/examples/axes_grid/demo_image.py branches/mathtex/examples/data/ branches/mathtex/lib/matplotlib/mpl-data/example/ Property Changed: ---------------- branches/mathtex/ branches/mathtex/doc/pyplots/README branches/mathtex/doc/sphinxext/gen_gallery.py branches/mathtex/doc/sphinxext/gen_rst.py branches/mathtex/examples/misc/multiprocess.py branches/mathtex/examples/mplot3d/contour3d_demo.py branches/mathtex/examples/mplot3d/contourf3d_demo.py branches/mathtex/examples/mplot3d/polys3d_demo.py branches/mathtex/examples/mplot3d/scatter3d_demo.py branches/mathtex/examples/mplot3d/surface3d_demo.py branches/mathtex/examples/mplot3d/wire3d_demo.py branches/mathtex/lib/matplotlib/sphinxext/mathmpl.py branches/mathtex/lib/matplotlib/sphinxext/only_directives.py branches/mathtex/lib/matplotlib/sphinxext/plot_directive.py Property changes on: branches/mathtex ___________________________________________________________________ Modified: svnmerge-integrated - /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-7253 /trunk/matplotlib:1-7332 + /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-7253 /trunk/matplotlib:1-7478 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 /trunk/matplotlib:7265-7303,7308-7317,7321 + /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,7442-7444,7446 /trunk/matplotlib:7265-7303,7308-7317,7321,7339-7478 Modified: branches/mathtex/CHANGELOG =================================================================== --- branches/mathtex/CHANGELOG 2009-08-12 19:17:09 UTC (rev 7478) +++ branches/mathtex/CHANGELOG 2009-08-12 23:30:13 UTC (rev 7479) @@ -1,5 +1,98 @@ -====================================================================== +2009-08-09 AnnotationBbox added. Similar to Annotation, but works with + OffsetBox instead of Text. See the example + demo_annotation_box.py. -JJL +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: + + draw_path_collection(self, master_transform, cliprect, clippath, + clippath_trans, paths, all_transforms, offsets, + offsetTrans, facecolors, edgecolors, linewidths, + linestyles, antialiaseds, urls) + + becomes: + + draw_path_collection(self, gc, master_transform, paths, all_transforms, + offsets, offsetTrans, facecolors, edgecolors, + linewidths, linestyles, antialiaseds, urls) + + + + draw_quad_mesh(self, master_transform, cliprect, clippath, + clippath_trans, meshWidth, meshHeight, coordinates, + offsets, offsetTrans, facecolors, antialiased, + showedges) + + becomes: + + draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight, + coordinates, offsets, offsetTrans, facecolors, + antialiased, showedges) + + + + draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None) + + becomes: + + draw_image(self, gc, x, y, im) + + - MGD + +2009-08-06 Tagging the 0.99.0 release at svn r7397 - JDH + + * fixed an alpha colormapping bug posted on sf 2832575 + + * fix typo in axes_divider.py. use nanmin, nanmax in angle_helper.py + (patch by Christoph Gohlke) + + * remove dup gui event in enter/leave events in gtk + + * lots of fixes for os x binaries (Thanks Russell Owen) + + * attach gtk events to mpl events -- fixes sf bug 2816580 + + * applied sf patch 2815064 (middle button events for wx) and + patch 2818092 (resize events for wx) + + * fixed boilerplate.py so it doesn't break the ReST docs. + + * removed a couple of cases of mlab.load + + * fixed rec2csv win32 file handle bug from sf patch 2831018 + + * added two examples from Josh Hemann: examples/pylab_examples/barchart_demo2.py + and examples/pylab_examples/boxplot_demo2.py + + * handled sf bugs 2831556 and 2830525; better bar error messages and + backend driver configs + + * added miktex win32 patch from sf patch 2820194 + + * apply sf patches 2830233 and 2823885 for osx setup and 64 bit; thanks Michiel + +2009-08-04 Made cbook.get_sample_data make use of the ETag and Last-Modified + headers of mod_dav_svn. - JKS + +2009-08-03 Add PathCollection; modify contourf to use complex + paths instead of simple paths with cuts. - EF + + +2009-08-03 Fixed boilerplate.py so it doesn't break the ReST docs. - JKS + +2009-08-03 pylab no longer provides a load and save function. These + are available in matplotlib.mlab, or you can use + numpy.loadtxt and numpy.savetxt for text files, or np.save + and np.load for binary numpy arrays. - JDH + +2009-07-31 Added cbook.get_sample_data for urllib enabled fetching and + cacheing of data needed for examples. See + examples/misc/sample_data_demo.py - JDH + 2009-07-31 Tagging 0.99.0.rc1 at 7314 - MGD 2009-07-30 Add set_cmap and register_cmap, and improve get_cmap, Modified: branches/mathtex/boilerplate.py =================================================================== --- branches/mathtex/boilerplate.py 2009-08-12 19:17:09 UTC (rev 7478) +++ branches/mathtex/boilerplate.py 2009-08-12 23:30:13 UTC (rev 7479) @@ -21,7 +21,6 @@ # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost def %(func)s(%(argspec)s): - %(docstring)s %(ax)s = gca() # allow callers to override the hold state by passing hold=True|False %(washold)s = %(ax)s.ishold() @@ -35,16 +34,19 @@ %(ax)s.hold(%(washold)s) %(mappable)s return %(ret)s +if Axes.%(func)s.__doc__ is not None: + %(func)s.__doc__ = dedent(Axes.%(func)s.__doc__) + __docstring_addendum """ _fmtmisc = """\ # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost def %(func)s(%(argspec)s): - %(docstring)s %(ret)s = gca().%(func)s(%(call)s) draw_if_interactive() return %(ret)s +if Axes.%(func)s.__doc__ is not None: + %(func)s.__doc__ = dedent(Axes.%(func)s.__doc__) """ # these methods are all simple wrappers of Axes methods by the same @@ -138,19 +140,6 @@ """ return '\n'.join(x.rstrip() for x in string.split('\n')) -def make_docstring(cmd, mention_hold): - func = getattr(Axes, cmd) - docstring = inspect.getdoc(func) - if docstring is None: - return "" - escaped = re.sub(r'\\', r'\\\\', docstring) - if mention_hold: - escaped += ''' - -Additional kwargs: hold = [True|False] overrides default hold state -''' - return '"""'+escaped+'"""' - for fmt,cmdlist in (_fmtplot,_plotcommands),(_fmtmisc,_misccommands): for func in cmdlist: # For some commands, an additional line is needed to set the @@ -160,9 +149,6 @@ else: mappable = '' - # Format docstring - docstring = make_docstring(func, fmt is _fmtplot) - # Get argspec of wrapped function args, varargs, varkw, defaults = inspect.getargspec(getattr(Axes, func)) args.pop(0) # remove 'self' argument Modified: branches/mathtex/doc/_templates/index.html =================================================================== --- branches/mathtex/doc/_templates/index.html 2009-08-12 19:17:09 UTC (rev 7478) +++ branches/mathtex/doc/_templates/index.html 2009-08-12 23:30:13 UTC (rev 7479) @@ -1,9 +1,9 @@ {% extends "layout.html" %} {% set title = 'matplotlib: python plotting' %} - + {% block body %} - <h1>Welcome</h1> + <h1>intro</h1> <p>matplotlib is a python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and @@ -41,7 +41,7 @@ <a href="http://scipy.org/Numpy_Example_List_With_Doc">numpy</a> and <a href="api/mlab_api.html">matplotlib.mlab</a>.</p> - <h3>Plotting commands</h3> <br/> + <h3>plotting commands</h3> <br/> <table border="1" cellpadding="3" cellspacing="2"> Modified: branches/mathtex/doc/_templates/indexsidebar.html =================================================================== --- branches/mathtex/doc/_templates/indexsidebar.html 2009-08-12 19:17:09 UTC (rev 7478) +++ branches/mathtex/doc/_templates/indexsidebar.html 2009-08-12 23:30:13 UTC (rev 7479) @@ -3,37 +3,33 @@ <p>Please <a href="http://sourceforge.net/project/project_donations.php?group_id=80706">donate</a> to support matplotlib development.</p> + +<p>matplotlib 0.99 is available for <a href="http://sourceforge.net/projects/matplotlib">download</a>. See <a href="{{ pathto('users/whats_new') }}">what's new</a> and tips on <a href="{{ +pathto('users/installing') }}">installing</a> +</p> - <p>Watch a <a href="http://videolectures.net/mloss08_hunter_mat">video lecture</a> about matplotlib presented at <a href="http://videolectures.net/mloss08_whistler">NIPS 08 Workshop</a> <i>Machine Learning Open Source Software</i></a>. </p> -<h3>Download</h3> -<p>Current version: <b>{{ version }}</b></p> - - -<p>Download matplotlib from the -sourceforge <a href="http://sourceforge.net/projects/matplotlib">project</a> -page (but first take a look at the <a href="{{ -pathto('users/installing') }}">installing</a> page). Here's a summary -of <a href="{{ pathto('users/whats_new') }}">what's new</a>. </p> - <p>There are several matplotlib addon <a href="{{ pathto('users/toolkits') }}">toolkits</a>, including the projection and mapping toolkit -<a href="http://matplotlib.sf.net/basemap/doc/html">basemap</a>.</p> +<a href="http://matplotlib.sf.net/basemap/doc/html">basemap</a>, 3d plotting with <a href="{{ +pathto('mpl_toolkits/mplot3d/index') }}">mplot3d</a>, wild and wonderful axes and axis helpers in <a href="{{ +pathto('mpl_toolkits/axes_grid/index') }}">axes_grid</a> and more. + </p> <h3>Need help?</h3> -<p>Check the <a href="{{ pathto('users/index') }}">user</a> guide, +<p>Check the <a href="{{ pathto('users/index') }}">user guide</a>, the <a href="{{ pathto('faq/index') }}">faq</a>, the <a href="{{ pathto('api/index') }}">api</a> docs, <a href="http://www.nabble.com/matplotlib---users-f2906.html">archives</a>, 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 Modified: branches/mathtex/doc/api/api_changes.rst =================================================================== --- branches/mathtex/doc/api/api_changes.rst 2009-08-12 19:17:09 UTC (rev 7478) +++ branches/mathtex/doc/api/api_changes.rst 2009-08-12 23:30:13 UTC (rev 7479) @@ -18,9 +18,51 @@ .. _configobj: http://www.voidspace.org.uk/python/configobj.html .. _`enthought.traits`: http://code.enthought.com/projects/traits -Changes beyond 0.98.x +Changes beyond 0.99.x ===================== +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:: + + draw_path_collection(self, master_transform, cliprect, clippath, + clippath_trans, paths, all_transforms, offsets, + offsetTrans, facecolors, edgecolors, linewidths, + linestyles, antialiaseds, urls) + + # is now + + draw_path_collection(self, gc, master_transform, paths, all_transforms, + offsets, offsetTrans, facecolors, edgecolors, + linewidths, linestyles, antialiaseds, urls) + + + draw_quad_mesh(self, master_transform, cliprect, clippath, + clippath_trans, meshWidth, meshHeight, coordinates, + offsets, offsetTrans, facecolors, antialiased, + showedges) + + # is now + + draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight, + coordinates, offsets, offsetTrans, facecolors, + antialiased, showedges) + + + draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None) + + # is now + + draw_image(self, gc, x, y, im) + +Changes in 0.99 +====================== + +* pylab no longer provides a load and save function. These are + available in matplotlib.mlab, or you can use numpy.loadtxt and + numpy.savetxt for text files, or np.save and np.load for binary + numpy arrays. + * User-generated colormaps can now be added to the set recognized by :func:`matplotlib.cm.get_cmap`. Colormaps can be made the default and applied to the current image using Modified: branches/mathtex/doc/api/spine_api.rst =================================================================== --- branches/mathtex/doc/api/spine_api.rst 2009-08-12 19:17:09 UTC (rev 7478) +++ branches/mathtex/doc/api/spine_api.rst 2009-08-12 23:30:13 UTC (rev 7479) @@ -4,7 +4,7 @@ :mod:`matplotlib.spine` -====================== +======================== .. automodule:: matplotlib.spine :members: Modified: branches/mathtex/doc/devel/coding_guide.rst =================================================================== --- branches/mathtex/doc/devel/coding_guide.rst 2009-08-12 19:17:09 UTC (rev 7478) +++ branches/mathtex/doc/devel/coding_guide.rst 2009-08-12 23:30:13 UTC (rev 7479) @@ -563,6 +563,45 @@ .. _license-discussion: + +Writing examples +================ + +We have hundreds of examples in subdirectories of +file:`matplotlib/examples` in the trunk, and these are automatically +generated when the website it built to show up both in the `examples +<http://matplotlib.sourceforge.net/examples/index.html>`_ and `gallery +<http://matplotlib.sourceforge.net/gallery.html>`_ sections of the +website. Many people find these examples from the website, and do not +have ready access to the file:`examples` directory in which they +reside. Thus any example data that is required for the example should +be provided through the sample_data svn directory, which can then be +accessed using :func:`matplotlib.cbook.get_sample_data`. First get a +copy of the repository and svn add your data:: + + svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk/sample_data + cp ~/path/to/mydata.dat sample_data/ + cd sample_data + svn add mydata.dat + svn commit -m 'added my data' + +and then in your example code you can load it into a file handle with:: + + import matplotlib.cbook as cbook + fh = cbook.get_sample_data('mydata.dat') + +The file will be fetched from the svn repo using urllib and updated +when the revision number changes. + + +If you prefer just to get the full path to the file instead of an file +object:: + + import matplotlib.cbook as cbook + datafile = cbook.get_sample_data('mydata.dat', asfileobj=False) + print 'datafile', datafile + + Licenses ======== @@ -630,3 +669,4 @@ extensions for scientific computing: ipython, numpy, scipy, the enthought tool suite and python itself are all distributed under BSD compatible licenses. +> \ No newline at end of file Modified: branches/mathtex/doc/faq/installing_faq.rst =================================================================== --- branches/mathtex/doc/faq/installing_faq.rst 2009-08-12 19:17:09 UTC (rev 7478) +++ branches/mathtex/doc/faq/installing_faq.rst 2009-08-12 23:30:13 UTC (rev 7479) @@ -287,11 +287,64 @@ <http://www.python.org/download/>`_. +.. _install_osx_binaries: + +Installing OSX binaries +----------------------- + +If you want to install matplotlib from one of the binary installers we +build, you have two choices: a dmg installer, which is a typical +Installer.app, or an binary OSX egg, which you can install via +setuptools easy_install. + +The mkpg installer will have a "dmg" extension, and will have a name +like :file:`matplotlib-0.99.0-py2.5-macosx10.5.dmg` depending on the +python, matplotlib, and OSX versions. Save this file and double +click it, which will open up a folder with a file in it that has the +mpkg extension. Double click this to run the Installer.app, which +will prompt you for a password if you need system wide installation +privileges, and install to a directory like +:file:`/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages`, +again depedending on your python version. This directory should be in +your python path, so you can test your installation with:: + + > python -c 'import matplotlib; print matplotlib.__version__, matplotlib.__file__' + +If you get an error like:: + + Traceback (most recent call last): + File "<string>", line 1, in <module> + ImportError: No module named matplotlib + +then you will need to set your PYTHONPATH, eg:: + + export PYTHONPATH=/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages:$PYTHONPATH + +See also :ref:`environment-variables`. + .. _easy-install-osx-egg: -easy_install from egg? +easy_install from egg ------------------------------ +You can also us the eggs we build for OSX (see the `installation +instructions +<http://pypi.python.org/pypi/setuptools#cygwin-mac-os-x-linux-other>`_ +for easy_install if you do not have it on your system already). You +can try:: + + > easy_install matplotlib + +which should grab the latest egg from the sourceforge site, but the +naming conventions for OSX eggs appear to be broken (see below) so +there is no guarantee the right egg will be found. We recommend you +download the latest egg from our `download site +<http://sourceforge.net/projects/matplotlib/files/>`_ directly to your +harddrive, and manually install it with + + > easy_install --install-dir=~/dev/lib/python2.5/site-packages/ matplotlib-0.99.0.rc1-py2.5-macosx-10.5-i386.egg + + Some users have reported problems with the egg for 0.98 from the matplotlib download site, with ``easy_install``, getting an error:: Property changes on: branches/mathtex/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 /trunk/matplotlib/doc/pyplots/README:7265-7303,7308-7317,7321 + /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,7442-7444,7446 /trunk/matplotlib/doc/pyplots/README:7265-7303,7308-7317,7321,7339-7478 Modified: branches/mathtex/doc/pyplots/plotmap.py =================================================================== --- branches/mathtex/doc/pyplots/plotmap.py 2009-08-12 19:17:09 UTC (rev 7478) +++ branches/mathtex/doc/pyplots/plotmap.py 2009-08-12 23:30:13 UTC (rev 7479) @@ -5,7 +5,9 @@ # the data is interpolated to the native projection grid. import os from mpl_toolkits.basemap import Basemap, shiftgrid -from pylab import title, colorbar, show, axes, cm, load, arange, figure, \ +import numpy as np + +from pylab import title, colorbar, show, axes, cm, arange, figure, \ text # read in topo data (on a regular lat/lon grid) @@ -15,9 +17,9 @@ if not os.path.exists(datadir): raise SystemExit('You need to download the data with svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk/htdocs/screenshots/data/" and set the datadir variable in %s'%__file__) -topoin = load(os.path.join(datadir, 'etopo20data.gz')) -lons = load(os.path.join(datadir, 'etopo20lons.gz')) -lats = load(os.path.join(datadir, 'etopo20lats.gz')) +topoin = np.loadtxt(os.path.join(datadir, 'etopo20data.gz')) +lons = np.loadtxt(os.path.join(datadir, 'etopo20lons.gz')) +lats = np.loadtxt(os.path.join(datadir, 'etopo20lats.gz')) # shift data so lons go from -180 to 180 instead of 20 to 380. topoin,lons = shiftgrid(180.,topoin,lons,start=False) Property changes on: branches/mathtex/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 /trunk/matplotlib/doc/sphinxext/gen_gallery.py:7265-7303,7308-7317,7321 + /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,7442-7444,7446 /trunk/matplotlib/doc/sphinxext/gen_gallery.py:7265-7303,7308-7317,7321,7339-7478 Property changes on: branches/mathtex/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 /trunk/matplotlib/doc/sphinxext/gen_rst.py:7265-7303,7308-7317,7321 + /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,7442-7444,7446 /trunk/matplotlib/doc/sphinxext/gen_rst.py:7265-7303,7308-7317,7321,7339-7478 Modified: branches/mathtex/doc/users/annotations.rst =================================================================== --- branches/mathtex/doc/users/annotations.rst 2009-08-12 19:17:09 UTC (rev 7478) +++ branches/mathtex/doc/users/annotations.rst 2009-08-12 23:30:13 UTC (rev 7479) @@ -3,6 +3,9 @@ Annotating text =============== +For a more detailed introduction to annotations, see +:ref:`plotting-guide-annotation`. + The uses of the basic :func:`~matplotlib.pyplot.text` command above place text at an arbitrary position on the Axes. A common use case of text is to annotate some feature of the plot, and the @@ -53,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 @@ -75,6 +81,7 @@ .. 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: branches/mathtex/doc/users/artists.rst =================================================================== --- branches/mathtex/doc/users/artists.rst 2009-08-12 19:17:09 UTC (rev 7478) +++ branches/mathtex/doc/users/artists.rst 2009-08-12 23:30:13 UTC (rev 7479) @@ -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: branches/mathtex/doc/users/credits.rst =================================================================== --- branches/mathtex/doc/users/credits.rst 2009-08-12 19:17:09 UTC (rev 7478) +++ branches/mathtex/doc/users/credits.rst 2009-08-12 23:30:13 UTC (rev 7479) @@ -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,11 @@ 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. Seppänen + 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 +170,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 Modified: branches/mathtex/doc/users/event_handling.rst =================================================================== --- branches/mathtex/doc/users/event_handling.rst 2009-08-12 19:17:09 UTC (rev 7478) +++ branches/mathtex/doc/users/event_handling.rst 2009-08-12 23:30:13 UTC (rev 7479) @@ -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 - ... [truncated message content] |