Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d513850

Browse files
committed
removed generator expression from mathtext2
svn path=/trunk/matplotlib/; revision=2747
1 parent 3eb61f6 commit d513850

3 files changed

Lines changed: 39 additions & 10 deletions

File tree

examples/poly_editor.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
"""
66
from matplotlib.artist import Artist
7-
from matplotlib.patches import Polygon
7+
from matplotlib.patches import Polygon, CirclePolygon
88
from matplotlib.numerix import sqrt, nonzero, equal, asarray, dot, Float
99
from matplotlib.numerix.mlab import amin
1010
from matplotlib.mlab import dist_point_to_segment
@@ -31,26 +31,34 @@ class PolygonInteractor:
3131
showverts = True
3232
epsilon = 5 # max pixel distance to count as a vertex hit
3333

34-
def __init__(self, poly):
34+
def __init__(self, ax, poly):
3535
if poly.figure is None:
3636
raise RuntimeError('You must first add the polygon to a figure or canvas before defining the interactor')
37+
self.ax = ax
3738
canvas = poly.figure.canvas
3839
self.poly = poly
3940
self.poly.verts = list(self.poly.verts)
4041
x, y = zip(*self.poly.verts)
41-
self.line = Line2D(x,y,marker='o', markerfacecolor='r')
42+
self.line = Line2D(x,y,marker='o', markerfacecolor='r', animated=True)
4243
#self._update_line(poly)
4344

4445
cid = self.poly.add_callback(self.poly_changed)
4546
self._ind = None # the active vert
4647

48+
canvas.mpl_connect('draw_event', self.draw_callback)
4749
canvas.mpl_connect('button_press_event', self.button_press_callback)
4850
canvas.mpl_connect('key_press_event', self.key_press_callback)
4951
canvas.mpl_connect('button_release_event', self.button_release_callback)
5052
canvas.mpl_connect('motion_notify_event', self.motion_notify_callback)
5153
self.canvas = canvas
5254

5355

56+
def draw_callback(self, event):
57+
self.background = self.canvas.copy_from_bbox(self.ax.bbox)
58+
self.ax.draw_artist(self.poly)
59+
self.ax.draw_artist(self.line)
60+
self.canvas.blit(self.ax.bbox)
61+
5462
def poly_changed(self, poly):
5563
'this method is called whenever the polygon object is called'
5664
# only copy the artist props to the line (except visibility)
@@ -123,7 +131,12 @@ def motion_notify_callback(self, event):
123131
x,y = event.xdata, event.ydata
124132
self.poly.verts[self._ind] = x,y
125133
self.line.set_data(zip(*self.poly.verts))
126-
self.canvas.draw_idle()
134+
135+
self.canvas.restore_region(self.background)
136+
self.ax.draw_artist(self.poly)
137+
self.ax.draw_artist(self.line)
138+
self.canvas.blit(self.ax.bbox)
139+
127140

128141

129142
from pylab import *
@@ -133,14 +146,14 @@ def motion_notify_callback(self, event):
133146

134147

135148
fig = figure()
136-
circ = Circle((.5,.5),.5)
149+
circ = CirclePolygon((.5,.5),.5, animated=True)
137150

138151

139152

140153

141154
ax = subplot(111)
142155
ax.add_patch(circ)
143-
p = PolygonInteractor( circ)
156+
p = PolygonInteractor( ax, circ)
144157

145158
ax.add_line(p.line)
146159
ax.set_title('Click and drag a point to move it')

lib/matplotlib/mathtext2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,8 @@ def render(self, x, y):
475475
self.sup.render(supx, supy)
476476

477477
def __repr__(self):
478-
tmp = (repr(i) for i in [self.env, self.nuc, self.type,
479-
self.sub, self.sup])
478+
tmp = [repr(i) for i in [self.env, self.nuc, self.type,
479+
self.sub, self.sup]]
480480
tmp = tuple(tmp)
481481
return "Scripted(env=%s,nuc=%s, type=%s, \
482482
sub=%s, sup=%s)"%tmp
@@ -850,4 +850,4 @@ def math_parse_s_ft2font1(s, dpi, fontsize, angle=0):
850850
texstring = _textclass(r"1_2^{4^5}32 5")
851851
parsed = parse_tex(texstring)
852852
#~ print bool(a)
853-
#print is_scriptcommand('\\subscript')
853+
#print is_scriptcommand('\\subscript')

lib/matplotlib/widgets.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,12 @@ def onselect(vmin, vmax):
792792
print vmin, vmax
793793
span = SpanSelector(ax, onselect, 'horizontal')
794794
795+
onmove_callback is an optional callback that will be called on mouse move
796+
with the span range
797+
795798
"""
796-
def __init__(self, ax, onselect, direction, minspan=None, useblit=False, rectprops=None):
799+
800+
def __init__(self, ax, onselect, direction, minspan=None, useblit=False, rectprops=None, onmove_callback=None):
797801
"""
798802
Create a span selector in ax. When a selection is made, clear
799803
the span and call onselect with
@@ -833,6 +837,7 @@ def __init__(self, ax, onselect, direction, minspan=None, useblit=False, rectpro
833837

834838
self.rectprops = rectprops
835839
self.onselect = onselect
840+
self.onmove_callback = onmove_callback
836841
self.useblit = useblit
837842
self.minspan = minspan
838843

@@ -928,6 +933,17 @@ def onmove(self, event):
928933
else:
929934
self.rect.xy[1] = minv
930935
self.rect.set_height(maxv-minv)
936+
937+
if self.onmove_callback is not None:
938+
vmin = self.pressv
939+
if self.direction == 'horizontal':
940+
vmax = event.xdata or self.prev[0]
941+
else:
942+
vmax = event.ydata or self.prev[1]
943+
944+
if vmin>vmax: vmin, vmax = vmax, vmin
945+
self.onmove_callback(vmin, vmax)
946+
931947
self.update()
932948
return False
933949

0 commit comments

Comments
 (0)