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

Skip to content

Commit 0daf594

Browse files
committed
updates to animation_bit
svn path=/trunk/matplotlib/; revision=1583
1 parent 4718a0d commit 0daf594

14 files changed

Lines changed: 245 additions & 144 deletions

API_CHANGES

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
API Changes in matplotlib-0.84
22

3-
Added flipud method to image and removed it from to_str.
3+
backend developers: Added flipud method to image and removed it
4+
from to_str. Removed origin kwarg from backend.draw_image.
5+
origin is handled entirely by the frontend now.
46

57
API Changes in matplotlib-0.83
68

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
New entries should be added at the top
22

3+
2005-08-04 Removed origin kwarg from backend.draw_image. origin is
4+
handled entirely by the frontend now.
5+
36
2005-07-03 Fixed a bug related to TeX commands in backend_ps
47

58
2005-08-03 Fixed SVG images to respect uppoer and lower origins.

examples/animation_blit.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# For detailed comments on animation and the techniqes used here, see
22
# the wiki entry
33
# http://www.scipy.org/wikis/topical_software/MatplotlibAnimation
4+
import matplotlib
5+
matplotlib.use('GTKAgg')
46
import sys
57
import gtk, gobject
68
import pylab as p
@@ -19,9 +21,17 @@
1921

2022
# save the clean slate background -- everything but the animated line
2123
# is drawn and saved in the pixel buffer background
22-
background = canvas.copy_from_bbox(ax.bbox)
24+
background = None
25+
26+
def snap_background(self):
27+
global background
28+
background = canvas.copy_from_bbox(ax.bbox)
29+
return True
30+
31+
p.connect('draw_event', snap_background)
2332

2433
def update_line(*args):
34+
if background is None: return True
2535
# restore the clean slate background
2636
canvas.restore_region(background)
2737
# update the data

examples/image_origin.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99

1010
x = arange(100.0); x.shape = 10,10
1111

12+
interp = 'bilinear';
13+
#interp = 'nearest';
1214
lim = -2,11,-2,6
1315
subplot(211, axisbg='g')
1416
title('blue should be up')
15-
imshow(x, origin='upper', interpolation='nearest')
17+
imshow(x, origin='upper', interpolation=interp)
1618
#axis(lim)
1719

1820
subplot(212, axisbg='y')
1921
title('blue should be down')
20-
imshow(x, origin='lower', interpolation='nearest')
22+
imshow(x, origin='lower', interpolation=interp)
2123
#axis(lim)
22-
savefig('image_origin.eps')
24+
savefig('image_origin')
2325
show()

lib/matplotlib/axes.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,20 +1366,16 @@ def draw(self, renderer, inframe=False):
13661366
# make a composite image blending alpha
13671367
# list of (_image.Image, ox, oy)
13681368

1369-
if not allequal([im.origin for im in self.images]):
1370-
raise ValueError('Composite images with different origins not supported')
1371-
else:
1372-
origin = self.images[0].origin
13731369

1374-
ims = [(im.make_image(renderer),0,0) for im in self.images if im.get_visible()]
1370+
ims = [(im.make_image(),0,0) for im in self.images if im.get_visible()]
13751371

13761372

13771373
im = _image.from_images(self.bbox.height(), self.bbox.width(), ims)
13781374
im.is_grayscale = False
13791375
l, b, w, h = self.bbox.get_bounds()
13801376
ox = l
13811377
oy = self.figure.bbox.height()-(b+h)
1382-
renderer.draw_image(ox, oy, im, origin, self.bbox)
1378+
renderer.draw_image(ox, oy, im, self.bbox)
13831379

13841380
if self.axison and not inframe:
13851381
self.xaxis.draw(renderer)

lib/matplotlib/backends/backend_gdk.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,15 @@ def draw_arc(self, gc, rgbFace, x, y, width, height, angle1, angle2):
9898
self.gdkDrawable.draw_arc(gc.gdkGC, False, x, y, w, h, a1, a2)
9999

100100

101-
def draw_image(self, x, y, im, origin, bbox):
101+
def draw_image(self, x, y, im, bbox):
102102
if bbox != None:
103103
l,b,w,h = bbox.get_bounds()
104104
#rectangle = (int(l), self.height-int(b+h),
105105
# int(w), int(h))
106106
# set clip rect?
107107

108-
if origin=='lower': flipud=1
109-
else: flipud=0
110-
rows, cols, image_str = im.as_rgba_str(flipud=flipud)
108+
im.flipud_out()
109+
rows, cols, image_str = im.as_rgba_str()
111110

112111
image_array = fromstring(image_str, UInt8)
113112
image_array.shape = rows, cols, 4
@@ -121,8 +120,8 @@ def draw_image(self, x, y, im, origin, bbox):
121120

122121
gc = self.new_gc()
123122

124-
if flipud:
125-
y = self.height-y-rows
123+
124+
y = self.height-y-rows
126125

127126
try: # new in 2.2
128127
# can use None instead of gc.gdkGC, if don't need clipping
@@ -135,6 +134,9 @@ def draw_image(self, x, y, im, origin, bbox):
135134
int(x), int(y), cols, rows,
136135
gdk.RGB_DITHER_NONE, 0, 0)
137136

137+
# unflip
138+
im.flipud_out()
139+
138140

139141
def draw_line(self, gc, x1, y1, x2, y2):
140142
self.gdkDrawable.draw_line(gc.gdkGC, int(x1), self.height-int(y1),

lib/matplotlib/backends/backend_ps.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -303,22 +303,18 @@ def _hex_lines(self, s, chars_per_line=128):
303303
lines.append(s[i:limit])
304304
return lines
305305

306-
def draw_image(self, x, y, im, origin, bbox):
306+
def draw_image(self, x, y, im, bbox):
307307
"""
308308
Draw the Image instance into the current axes; x is the
309-
distance in pixels from the left hand side of the canvas. y is
310-
the distance from the origin. That is, if origin is upper, y
311-
is the distance from top. If origin is lower, y is the
312-
distance from bottom
313-
314-
origin is 'upper' or 'lower'
309+
distance in pixels from the left hand side of the canvas and y
310+
is the distance from bottom
315311
316312
bbox is a matplotlib.transforms.BBox instance for clipping, or
317313
None
318314
"""
319315

320-
flipud = origin=='lower'
321-
if flipud: im.flipud()
316+
im.flipud_out()
317+
322318
if im.is_grayscale:
323319
h, w, bits = self._gray(im)
324320
imagecmd = "image"
@@ -334,7 +330,7 @@ def draw_image(self, x, y, im, origin, bbox):
334330
if bbox is not None:
335331
clipx,clipy,clipw,cliph = bbox.get_bounds()
336332
clip = '%s clipbox' % _nums_to_str(clipw, cliph, clipx, clipy)
337-
if not flipud: y = figh-(y+h)
333+
#y = figh-(y+h)
338334
ps = """gsave
339335
%(clip)s
340336
%(x)s %(y)s translate
@@ -348,7 +344,9 @@ def draw_image(self, x, y, im, origin, bbox):
348344
grestore
349345
""" % locals()
350346
self._pswriter.write(ps)
351-
347+
348+
# unflip
349+
im.flipud_out()
352350
def draw_line(self, gc, x0, y0, x1, y1):
353351
"""
354352
Draw a single line from x0,y0 to x1,y1

lib/matplotlib/backends/backend_svg.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def draw_arc(self, gc, rgbFace, x, y, width, height, angle1, angle2):
124124
details = 'cx="%f" cy="%f" r="%f"' % (x,self.height-y,width/2)
125125
self._draw_svg_element('circle', details, gc, rgbFace)
126126

127-
def draw_image(self, x, y, im, origin, bbox):
127+
def draw_image(self, x, y, im, bbox):
128128
filename = os.path.join (tempfile.gettempdir(),
129129
tempfile.gettempprefix() + '.png'
130130
)
@@ -138,11 +138,10 @@ def draw_image(self, x, y, im, origin, bbox):
138138
# to provide one. I suspect there is a way, but I don't know
139139
# it
140140

141-
flipud = origin=='lower'
141+
im.flipud_out()
142+
142143
h,w = im.get_size_out()
143-
if flipud:
144-
im.flipud()
145-
y = self.height-y-h
144+
y = self.height-y-h
146145
im.write_png(filename)
147146

148147
imfile = file (filename, 'r')
@@ -157,6 +156,9 @@ def draw_image(self, x, y, im, origin, bbox):
157156
% (x, y, w+1, h+1, '\n'.join(lines))
158157
)
159158

159+
# unflip
160+
im.flipud_out()
161+
160162
def draw_line(self, gc, x1, y1, x2, y2):
161163
details = 'd="M %f,%f L %f,%f"' % (x1, self.height-y1,
162164
x2, self.height-y2)

lib/matplotlib/backends/backend_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class RendererTemplate(RendererBase):
7272
def draw_arc(self, gcEdge, rgbFace, x, y, width, height, angle1, angle2):
7373
pass
7474

75-
def draw_image(self, x, y, im, origin, bbox):
75+
def draw_image(self, x, y, im, bbox):
7676
pass
7777

7878
def draw_line(self, gc, x1, y1, x2, y2):

lib/matplotlib/image.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def changed(self):
117117
self._imcache = None
118118
cm.ScalarMappable.changed(self)
119119

120-
def make_image(self, flipy):
120+
def make_image(self):
121121
if self._A is not None:
122122
if self._imcache is None:
123123
if self._A.typecode() == UInt8:
@@ -133,6 +133,10 @@ def make_image(self, flipy):
133133

134134

135135
bg = colorConverter.to_rgba(self.axes.get_frame().get_facecolor(), 0)
136+
137+
if self.origin=='upper':
138+
im.flipud_in()
139+
136140
im.set_bg( *bg)
137141
im.is_grayscale = (self.cmap.name == "gray" and
138142
len(self._A.shape) == 2)
@@ -159,10 +163,13 @@ def make_image(self, flipy):
159163

160164
# the viewport translation
161165
tx = (xmin-self.axes.viewLim.xmin())/dxintv * numcols
162-
if flipy:
163-
ty = -(ymax-self.axes.viewLim.ymax())/dyintv * numrows
164-
else:
165-
ty = (ymin-self.axes.viewLim.ymin())/dyintv * numrows
166+
167+
168+
#if flipy:
169+
# ty = -(ymax-self.axes.viewLim.ymax())/dyintv * numrows
170+
#else:
171+
# ty = (ymin-self.axes.viewLim.ymin())/dyintv * numrows
172+
ty = (ymin-self.axes.viewLim.ymin())/dyintv * numrows
166173

167174
l, b, widthDisplay, heightDisplay = self.axes.bbox.get_bounds()
168175

@@ -186,13 +193,16 @@ def make_image(self, flipy):
186193
#print tx, ty, sx, sy, rx, ry, widthDisplay, heightDisplay
187194
im.resize(int(widthDisplay+0.5), int(heightDisplay+0.5),
188195
norm=self._filternorm, radius=self._filterrad)
196+
197+
if self.origin=='upper':
198+
im.flipud_in()
199+
189200
return im
190201

191-
def draw(self, renderer, *args, **kwargs):
202+
def __draw(self, renderer, *args, **kwargs):
192203
if not self.get_visible(): return
193204
isUpper = self.origin=='upper'
194205
flipy = renderer.flipy()
195-
196206
im = self.make_image(isUpper)
197207
l, b, widthDisplay, heightDisplay = self.axes.bbox.get_bounds()
198208
if isUpper:
@@ -204,6 +214,12 @@ def draw(self, renderer, *args, **kwargs):
204214
oy = b
205215
renderer.draw_image(l, oy, im, self.origin, self.axes.bbox)
206216

217+
def draw(self, renderer, *args, **kwargs):
218+
if not self.get_visible(): return
219+
im = self.make_image()
220+
l, b, widthDisplay, heightDisplay = self.axes.bbox.get_bounds()
221+
renderer.draw_image(l, b, im, self.axes.bbox)
222+
207223
def write_png(self, fname):
208224
"""Write the image to png file with fname"""
209225
im = self.make_image(False)

0 commit comments

Comments
 (0)