Skip to content

Commit 44afb02

Browse files
committed
added poly interactor
svn path=/trunk/matplotlib/; revision=1784
1 parent 1ed561d commit 44afb02

File tree

8 files changed

+141
-21
lines changed

8 files changed

+141
-21
lines changed

CXX/cxx_extensions.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ PythonExtensionBase::PythonExtensionBase()
10721072

10731073
PythonExtensionBase::~PythonExtensionBase()
10741074
{
1075-
assert( ob_refcnt == 0 );
1075+
//assert( ob_refcnt == 0 );
10761076
}
10771077

10781078
int PythonExtensionBase::print( FILE *, int )

LICENSE/LICENSE

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
LICENSE AGREEMENT FOR MATPLOTLIB 0.83.2
1+
LICENSE AGREEMENT FOR MATPLOTLIB 0.84
22
--------------------------------------
33

44
1. This LICENSE AGREEMENT is between John D. Hunter ("JDH"), and the
@@ -9,30 +9,30 @@ documentation.
99
2. Subject to the terms and conditions of this License Agreement, JDH
1010
hereby grants Licensee a nonexclusive, royalty-free, world-wide license
1111
to reproduce, analyze, test, perform and/or display publicly, prepare
12-
derivative works, distribute, and otherwise use matplotlib 0.83.2
12+
derivative works, distribute, and otherwise use matplotlib 0.84
1313
alone or in any derivative version, provided, however, that JDH's
1414
License Agreement and JDH's notice of copyright, i.e., "Copyright (c)
1515
2002-2005 John D. Hunter; All Rights Reserved" are retained in
16-
matplotlib 0.83.2 alone or in any derivative version prepared by
16+
matplotlib 0.84 alone or in any derivative version prepared by
1717
Licensee.
1818

1919
3. In the event Licensee prepares a derivative work that is based on or
20-
incorporates matplotlib 0.83.2 or any part thereof, and wants to
20+
incorporates matplotlib 0.84 or any part thereof, and wants to
2121
make the derivative work available to others as provided herein, then
2222
Licensee hereby agrees to include in any such work a brief summary of
23-
the changes made to matplotlib 0.83.2.
23+
the changes made to matplotlib 0.84.
2424

25-
4. JDH is making matplotlib 0.83.2 available to Licensee on an "AS
25+
4. JDH is making matplotlib 0.84 available to Licensee on an "AS
2626
IS" basis. JDH MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
2727
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, JDH MAKES NO AND
2828
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
29-
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF MATPLOTLIB 0.83.2
29+
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF MATPLOTLIB 0.84
3030
WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.
3131

3232
5. JDH SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF MATPLOTLIB
33-
0.83.2 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR
33+
0.84 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR
3434
LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING
35-
MATPLOTLIB 0.83.2, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF
35+
MATPLOTLIB 0.84, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF
3636
THE POSSIBILITY THEREOF.
3737

3838
6. This License Agreement will automatically terminate upon a material
@@ -44,6 +44,6 @@ Licensee. This License Agreement does not grant permission to use JDH
4444
trademarks or trade name in a trademark sense to endorse or promote
4545
products or services of Licensee, or any third party.
4646

47-
8. By copying, installing or otherwise using matplotlib 0.83.2,
47+
8. By copying, installing or otherwise using matplotlib 0.84,
4848
Licensee agrees to be bound by the terms and conditions of this License
4949
Agreement.

examples/backend_driver.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ def drive(backend, python='python2.4'):
130130
# backends = ['Agg', 'Cairo', 'GDK', 'PS', 'SVG', 'Template']
131131
backends = ['Agg', 'PS', 'SVG', 'Template']
132132
# backends = [ 'GTK', 'WX', 'TkAgg']
133-
#backends = ['Agg', 'PS', 'SVG', 'Template']
134-
backends = ['SVG']
133+
backends = ['Agg', 'PS', 'SVG', 'Template']
134+
#backends = ['SVG']
135135
python = 'python2.4'
136136
for backend in backends:
137137
print 'testing %s' % backend

examples/image_demo.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
X, Y = meshgrid(x, y)
77
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
88
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
9+
Z = Z2-Z1 # difference of Gaussians
10+
11+
im = imshow(Z, interpolation='bilinear', cmap=cm.gray,
12+
origin='lower', extent=[-3,3,-3,3])
913

10-
# difference of Gaussians
11-
im = imshow(Z2-Z1, interpolation='bilinear', origin='lower')
12-
#axis('off')
1314
show()
1415

lib/matplotlib/lines.py

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from artist import Artist, setp
1919
from cbook import iterable, is_string_like
2020
from colors import colorConverter
21-
from patches import bbox_artist
2221

2322
from transforms import lbwh_to_bbox, LOG10
2423
from matplotlib import rcParams
@@ -382,7 +381,6 @@ def draw(self, renderer):
382381
markerFunc = getattr(self, funcname)
383382
markerFunc(renderer, gc, xt, yt)
384383

385-
#if 1: bbox_artist(self, renderer)
386384
#renderer.close_group('line2d')
387385

388386
def get_antialiased(self): return self._antialiased

lib/matplotlib/patches.py

+121-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
from __future__ import division
22
import math
33
from matplotlib import rcParams
4-
from numerix import array, arange, sin, cos, pi, Float, sqrt, matrixmultiply
4+
from numerix import array, arange, sin, cos, pi, Float, sqrt, \
5+
matrixmultiply, sqrt, nonzero, equal, asarray, dot
56
from artist import Artist, setp
67
from cbook import enumerate, popd
78
from colors import colorConverter
9+
from lines import Line2D
810
from transforms import bound_vertices
911

12+
from numerix.mlab import amin
13+
from mlab import dist_point_to_segment
14+
15+
1016
class Patch(Artist):
1117
"""
1218
A patch is a 2D thingy with a face color and an edge color
@@ -418,6 +424,120 @@ def __init__(self, xy, radius=5,
418424
orientation=0,
419425
**kwargs)
420426

427+
class PolygonInteractor:
428+
"""
429+
An polygon editor.
430+
431+
Key-bindings
432+
433+
't' toggle vertex markers on and off. When vertex markers are on,
434+
you can move them, delete them
435+
436+
'd' delete the vertex under point
437+
438+
'i' insert a vertex at point. You must be within epsilon of the
439+
line connecting two existing vertices
440+
441+
"""
442+
443+
showverts = True
444+
epsilon = 5 # max pixel distance to count as a vertex hit
445+
446+
def __init__(self, poly):
447+
if poly.figure is None:
448+
raise RuntimeError('You must first add the polygon to a figure or canvas before defining the interactor')
449+
canvas = poly.figure.canvas
450+
self.poly = poly
451+
self.poly.verts = list(self.poly.verts)
452+
x, y = zip(*self.poly.verts)
453+
self.line = Line2D(x,y,marker='o', markerfacecolor='r')
454+
#self._update_line(poly)
455+
456+
cid = self.poly.add_callback(self.poly_changed)
457+
self._ind = None # the active vert
458+
459+
canvas.mpl_connect('button_press_event', self.button_press_callback)
460+
canvas.mpl_connect('key_press_event', self.key_press_callback)
461+
canvas.mpl_connect('button_release_event', self.button_release_callback)
462+
canvas.mpl_connect('motion_notify_event', self.motion_notify_callback)
463+
self.canvas = canvas
464+
465+
466+
def poly_changed(self, poly):
467+
'this method is called whenever the polygon object is called'
468+
# only copy the artist props to the line (except visibility)
469+
vis = self.line.get_visible()
470+
Artist.update_from(self.line, poly)
471+
self.line.set_visible(vis) # don't use the poly visibility state
472+
473+
474+
def get_ind_under_point(self, event):
475+
'get the index of the vertex under point if within epsilon tolerance'
476+
x, y = zip(*self.poly.verts)
477+
478+
# display coords
479+
xt, yt = self.poly.get_transform().numerix_x_y(x, y)
480+
d = sqrt((xt-event.x)**2 + (yt-event.y)**2)
481+
indseq = nonzero(equal(d, amin(d)))
482+
ind = indseq[0]
483+
484+
if d[ind]>=self.epsilon:
485+
ind = None
486+
487+
return ind
488+
489+
def button_press_callback(self, event):
490+
'whenever a mouse button is pressed'
491+
if not self.showverts: return
492+
if event.inaxes==None: return
493+
if event.button != 1: return
494+
self._ind = self.get_ind_under_point(event)
495+
496+
def button_release_callback(self, event):
497+
'whenever a mouse button is released'
498+
if not self.showverts: return
499+
if event.button != 1: return
500+
self._ind = None
501+
502+
def key_press_callback(self, event):
503+
'whenever a key is pressed'
504+
if not event.inaxes: return
505+
if event.key=='t':
506+
self.showverts = not self.showverts
507+
self.line.set_visible(self.showverts)
508+
if not self.showverts: self._ind = None
509+
elif event.key=='d':
510+
ind = self.get_ind_under_point(event)
511+
if ind is not None:
512+
self.poly.verts = [tup for i,tup in enumerate(self.poly.verts) if i!=ind]
513+
self.line.set_data(zip(*self.poly.verts))
514+
elif event.key=='i':
515+
xys = self.poly.get_transform().seq_xy_tups(self.poly.verts)
516+
p = event.x, event.y # display coords
517+
for i in range(len(xys)-1):
518+
s0 = xys[i]
519+
s1 = xys[i+1]
520+
d = dist_point_to_segment(p, s0, s1)
521+
if d<=self.epsilon:
522+
self.poly.verts.insert(i+1, (event.xdata, event.ydata))
523+
self.line.set_data(zip(*self.poly.verts))
524+
break
525+
526+
527+
self.canvas.draw()
528+
529+
def motion_notify_callback(self, event):
530+
'on mouse movement'
531+
if not self.showverts: return
532+
if self._ind is None: return
533+
if event.inaxes is None: return
534+
if event.button != 1: return
535+
x,y = event.xdata, event.ydata
536+
self.poly.verts[self._ind] = x,y
537+
self.line.set_data(zip(*self.poly.verts))
538+
self.canvas.draw_idle()
539+
540+
421541
def bbox_artist(artist, renderer, props=None, fill=True):
422542
"""
423543
This is a debug function to draw a rectangle around the bounding

lib/matplotlib/pylab.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,8 @@ def axes(*args, **kwargs):
624624
frameon=False : don't display the frame
625625
sharex=otherax : the current axes shares xaxis attribute with otherax
626626
sharey=otherax : the current axes shares yaxis attribute with otherax
627-
627+
polar=True|False : use a polar axes or not
628+
628629
Examples
629630
630631
examples/axes_demo.py places custom axes.

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
BUILD_WINDOWING = 'auto'
4343

4444

45-
VERBOSE = True # insert lots of diagnostic prints in extension code
45+
VERBOSE = False # insert lots of diagnostic prints in extension code
4646

4747

4848

0 commit comments

Comments
 (0)