SF.net SVN: matplotlib:[5792] trunk/py4science/examples/numpy_wrap/f2py
Revision: 5792 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5792&view=rev Author: fer_perez Date: 2008-07-19 07:05:43 + (Sat, 19 Jul 2008) Log Message: --- Add a new f2py example that uses F90 (it's still very simple). Added Paths: --- trunk/py4science/examples/numpy_wrap/f2py/example4/ trunk/py4science/examples/numpy_wrap/f2py/example4/Makefile trunk/py4science/examples/numpy_wrap/f2py/example4/README.txt trunk/py4science/examples/numpy_wrap/f2py/example4/setup.cfg trunk/py4science/examples/numpy_wrap/f2py/example4/setup.py trunk/py4science/examples/numpy_wrap/f2py/example4/simple.f90 trunk/py4science/examples/numpy_wrap/f2py/example4/simple.pyf trunk/py4science/examples/numpy_wrap/f2py/example4/test_simple.py Added: trunk/py4science/examples/numpy_wrap/f2py/example4/Makefile === --- trunk/py4science/examples/numpy_wrap/f2py/example4/Makefile (rev 0) +++ trunk/py4science/examples/numpy_wrap/f2py/example4/Makefile 2008-07-19 07:05:43 UTC (rev 5792) @@ -0,0 +1,39 @@ +# Python wrappers for a simple Fortran 90 library + +# Build the actual library using a standard Python setup.py script +build: simple.so + +simple.so: simple.f90 simple.pyf setup.py + ./setup.py config_fc build_ext --inplace + +# Build the library in place via a direct call to f2py, using the manually +# modified simple.pyf file. +libpyf: simple.f90 simple.pyf + f2py -c --fcompiler=gnu95 simple.pyf simple.f90 + +# Build the 'raw' library by hand, without any tweaks to the python interface +# of any function. Note that this will NOT pass the tests, since the tests +# expect the modified interface. +libraw: simple.f90 + f2py -c --fcompiler=gnu95 -m simple simple.f90 + +# Run a very simple test. +test: build + python test_simple.py + +# If you have nose installed, the test above can be run as a proper unittest. +nose: build + nosetests test_simple.py + +# Build the .pyf file. Note that the supplied file simple.pyf has been +# manually modified from the auto-generated one. It's a good idea to +# auto-generate one with a different name if you intend to manually edit yours +# later, to help prevent an accidental clobbering. +pyf: simple.f90 + f2py -h simple_auto.pyf -m simple simple.f90 + +clean: + rm -rf *~ *module.c *.pyc *-f2pywrappers*.f90 build + +cleanall: clean + rm -rf *.so Added: trunk/py4science/examples/numpy_wrap/f2py/example4/README.txt === --- trunk/py4science/examples/numpy_wrap/f2py/example4/README.txt (rev 0) +++ trunk/py4science/examples/numpy_wrap/f2py/example4/README.txt 2008-07-19 07:05:43 UTC (rev 5792) @@ -0,0 +1,24 @@ +== + Very simple Fortran 90 wrapping example via f2py +== + +This small, self-contained directory shows how to build an extension for Python +based on Fortran 90 code. You can do it both by directly calling f2py and via +a small setup.py file. + +See the accompanying makefile for the actual targets provided, but if you are +impatient and have gfortran installed, simply type:: + +make test + +which should run the build and a simple test. If no errors are printed at the +end, you're fine. If you have nose installed (highly recommended and needed to +test numpy and scipy, see +http://www.somethingaboutorange.com/mrl/projects/nose/) you can try instead:: + +make nose + +This will run the same test files but as proper tests, indicating number of +tests, errors/failures, etc. There is currently only one test provided, but +using this in your projects will get you going with proper testing practices +from the start. Added: trunk/py4science/examples/numpy_wrap/f2py/example4/setup.cfg === --- trunk/py4science/examples/numpy_wrap/f2py/example4/setup.cfg (rev 0) +++ trunk/py4science/examples/numpy_wrap/f2py/example4/setup.cfg 2008-07-19 07:05:43 UTC (rev 5792) @@ -0,0 +1,2 @@ +[config_fc] +fcompiler = gnu95 Added: trunk/py4science/examples/numpy_wrap/f2py/example4/setup.py === --- trunk/py4science/examples/numpy_wrap/f2py/example4/setup.py (rev 0) +++ trunk/py4science/examples/numpy_wrap/f2py/example4/setup.py 2008-07-19 07:05:43 UTC (rev 5792) @@ -0,0 +1,32 @@ +#!/usr/bin/env python +"""Setup script for f2py-wrapped library. +""" + +# Third-party modules +from numpy.distutils.core import setup +from numpy.distutils.extension import Extension + +# Build the extension module object +extmod = Extension( name = 'simple', +# List here the interface (.pyf) file, plus any sources +
SF.net SVN: matplotlib:[5793] trunk/matplotlib/lib/matplotlib/contour.py
Revision: 5793
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5793&view=rev
Author: efiring
Date: 2008-07-20 00:57:41 + (Sun, 20 Jul 2008)
Log Message:
---
Reverting clabel-related change in contour.py to 5689.
contour_demo.py was broken.
Modified Paths:
--
trunk/matplotlib/lib/matplotlib/contour.py
Modified: trunk/matplotlib/lib/matplotlib/contour.py
===
--- trunk/matplotlib/lib/matplotlib/contour.py 2008-07-19 07:05:43 UTC (rev
5792)
+++ trunk/matplotlib/lib/matplotlib/contour.py 2008-07-20 00:57:41 UTC (rev
5793)
@@ -17,9 +17,6 @@
import matplotlib.text as text
import matplotlib.cbook as cbook
-# Import needed for adding manual selection capability to clabel
-from matplotlib.blocking_input import BlockingContourLabeler
-
# We can't use a single line collection for contour because a line
# collection can have only a single line style, and we want to be able to have
# dashed negative contours, for example, and solid positive contours.
@@ -71,17 +68,7 @@
*fmt*:
a format string for the label. Default is '%1.3f'
-Alternatively, this can be a dictionary matching contour
-levels with arbitrary strings to use for each contour level
-(i.e., fmt[level]=string)
- *manual*:
-if *True*, contour labels will be placed manually using
-mouse clicks. Click the first button near a contour to
-add a label, click the second button (or potentially both
-mouse buttons at once) to finish adding labels. The third
-button can be used to remove the last label added, but
-only if labels are not inline.
"""
fontsize = kwargs.get('fontsize', None)
@@ -89,9 +76,8 @@
self.fmt = kwargs.get('fmt', '%1.3f')
_colors = kwargs.get('colors', None)
-# Detect if manual selection is desired and remove from argument list
-self.manual_select=kwargs.get('manual',False)
+
if len(args) == 0:
levels = self.levels
indices = range(len(self.levels))
@@ -140,16 +126,10 @@
#self.cl_cvalues = [] # same
self.cl_xy = []
-if self.manual_select:
-print 'Select label locations manually using first mouse button.'
-print 'End manual selection with second mouse button.'
-if not inline:
-print 'Remove last label by clicking third mouse button.'
+self.labels(inline)
-blocking_contour_labeler = BlockingContourLabeler(self)
-blocking_contour_labeler(inline)
-else:
-self.labels(inline)
+for label in self.cl:
+self.ax.add_artist(label)
self.label_list = cbook.silent_list('text.Text', self.cl)
return self.label_list
@@ -161,10 +141,10 @@
if lcsize > 10 * labelwidth:
return 1
-xmax = np.amax(linecontour[:,0])
-xmin = np.amin(linecontour[:,0])
-ymax = np.amax(linecontour[:,1])
-ymin = np.amin(linecontour[:,1])
+xmax = np.amax(np.array(linecontour)[:,0])
+xmin = np.amin(np.array(linecontour)[:,0])
+ymax = np.amax(np.array(linecontour)[:,1])
+ymin = np.amin(np.array(linecontour)[:,1])
lw = labelwidth
if (xmax - xmin) > 1.2* lw or (ymax - ymin) > 1.2 * lw:
@@ -213,7 +193,7 @@
if cbook.is_string_like(lev):
lw = (len(lev)) * fsize
else:
-lw = (len(self.get_text(lev,fmt))) * fsize
+lw = (len(fmt%lev)) * fsize
return lw
@@ -230,11 +210,9 @@
if cbook.is_string_like(lev):
return lev
else:
-if isinstance(fmt,dict):
-return fmt[lev]
-else:
-return fmt%lev
+return fmt%lev
+
def break_linecontour(self, linecontour, rot, labelwidth, ind):
"break a contour in two contours at the location of the label"
lcsize = len(linecontour)
@@ -248,8 +226,8 @@
slc = trans.transform(linecontour)
x,y = slc[ind]
-xx=slc[:,0].copy()
-yy=slc[:,1].copy()
+xx= np.asarray(slc)[:,0].copy()
+yy=np.asarray(slc)[:,1].copy()
#indices which are under the label
inds, = np.nonzero(((xx < x+xlabel) & (xx > x-xlabel)) &
@@ -330,8 +308,8 @@
else:
ysize = labelwidth
-XX = np.resize(linecontour[:,0],(xsize, ysize))
-YY = np.resize(linecontour[:,1],(xsize, ysize))
+XX = np.resize(np.asarray(linecontour)[:,0],(xsize, ysize))
+YY = np.resize(np.asarray(linecontour)[:,1],(xsize, ysize))
#I might have fouled up the following:
yfirst = YY[:,0].reshape(xsize, 1)
ylast = YY[:,-1].reshape(xsize, 1)
@@ -357,85 +335,19 @@
return x,y, rotation
