Revision: 5793
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5793&view=rev
Author:   efiring
Date:     2008-07-20 00:57:41 +0000 (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, dind
 
-    def add_label(self,x,y,rotation,icon):
-        dx,dy = self.ax.transData.inverted().transform_point((x,y))
-        t = text.Text(dx, dy, rotation = rotation,
-                      horizontalalignment='center',
-                      verticalalignment='center')
-
-        color = self.label_mappable.to_rgba(self.label_cvalues[icon],
-                                            alpha=self.alpha)
-
-        _text = self.get_text(self.label_levels[icon],self.fmt)
-        self.set_label_props(t, _text, color)
-        self.cl.append(t)
-        self.cl_cvalues.append(self.label_cvalues[icon])
-        
-        # Add label to plot here - useful for manual mode label selection
-        self.ax.add_artist(t)
-
-    def pop_label(self,index=-1):
-        '''Defaults to removing last label, but any index can be supplied'''
-        self.cl_cvalues.pop(index)
-        t = self.cl.pop(index)
-        t.remove()
-
-    def find_nearest_contour( self, x, y, pixel=True ):
-        """
-        Finds contour that is closest to a point.  Defaults to
-        measuring distance in pixels (screen space - useful for manual
-        contour labeling), but this can be controlled via a keyword
-        argument.
-
-        Returns a tuple containing the contour, segment, index of
-        segment, x & y of segment point and distance to minimum point.
-        """
-
-        # This function uses a method that is probably quite
-        # inefficient based on converting each contour segment to
-        # pixel coordinates and then comparing the given point to
-        # those coordinates for each contour.  This will probably be
-        # quite slow for complex contours, but for normal use it works
-        # sufficiently well that the time is not noticeable.
-        # Nonetheless, improvements could probably be made.
-
-        dmin = 1e10
-        conmin = None
-        segmin = None
-        xmin = None
-        ymin = None
-
-        for icon in self.label_indices:
-            con = self.collections[icon]
-            paths = con.get_paths()
-            for segNum, linepath in enumerate(paths):
-                lc = linepath.vertices
-
-                # transfer all data points to screen coordinates if desired
-                if pixel:
-                    lc = self.ax.transData.transform(lc)
-                
-                ds = (lc[:,0]-x)**2 + (lc[:,1]-y)**2
-                d = min( ds )
-                if d < dmin:
-                    dmin = d
-                    conmin = icon
-                    segmin = segNum
-                    imin = mpl.mlab.find( ds == d )[0]
-                    xmin = lc[imin,0]
-                    ymin = lc[imin,1]
-
-        return (conmin,segmin,imin,xmin,ymin,dmin)
-
     def labels(self, inline):
         levels = self.label_levels
         fslist = self.fslist
         trans = self.ax.transData
-
-        for icon, lev, fsize in zip(self.label_indices,
-                                    self.label_levels, fslist):
+        _colors = self.label_mappable.to_rgba(self.label_cvalues,
+                                                        alpha=self.alpha)
+        fmt = self.fmt
+        for icon, lev, color, cvalue, fsize in zip(self.label_indices,
+                                          self.label_levels,
+                                          _colors,
+                                          self.label_cvalues, fslist):
             con = self.collections[icon]
-            lw = self.get_label_width(lev, self.fmt, fsize)
+            lw = self.get_label_width(lev, fmt, fsize)
             additions = []
             paths = con.get_paths()
             for segNum, linepath in enumerate(paths):
@@ -450,8 +362,16 @@
                 slc = trans.transform(linecontour)
                 if self.print_label(slc,lw):
                     x,y, rotation, ind  = self.locate_label(slc, lw)
-                    self.add_label(x,y,rotation,icon)
-
+                    # transfer the location of the label back to
+                    # data coordinates
+                    dx,dy = trans.inverted().transform_point((x,y))
+                    t = text.Text(dx, dy, rotation = rotation,
+                             horizontalalignment='center',
+                             verticalalignment='center')
+                    _text = self.get_text(lev,fmt)
+                    self.set_label_props(t, _text, color)
+                    self.cl.append(t)
+                    self.cl_cvalues.append(cvalue)
                     if inline:
                         new = self.break_linecontour(linecontour, rotation, 
lw, ind)
                         if len(new[0]):
@@ -882,8 +802,19 @@
         Use keyword args to control colors, linewidth, origin, cmap ... see
         below for more details.
 
-        *X*, *Y*, and *Z* must be arrays with the same dimensions.
+        *X*, *Y*, and *Z* may be arrays all with the same 2-D shape, or
+        *X* and *Y* can be 1-D while *Z* is 2-D.  In the latter
+        case, the following must be true:
 
+        ::
+
+          Z.shape == len(Y), len(X)
+
+        Note that the first index of *Z*, the row number, corresponds
+        to the vertical coordinate on the page, while the second
+        index, the column number, corresponds to the horizontal
+        coordinate on the page.
+
         *Z* may be a masked array, but filled contouring may not
         handle internal masked regions correctly.
 


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

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to