Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 43bb86d

Browse filesBrowse files
committed
plugged image resize mem leaks
svn path=/trunk/matplotlib/; revision=872
1 parent be2d36d commit 43bb86d
Copy full SHA for 43bb86d

File tree

Expand file treeCollapse file tree

10 files changed

+219
-123
lines changed
Filter options
Expand file treeCollapse file tree

10 files changed

+219
-123
lines changed

‎CHANGELOG

Copy file name to clipboardExpand all lines: CHANGELOG
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
New entries should be added at the top
22

3+
2005-01-18 Plugged an image resize memory leaks - JDH
4+
5+
2005-01-18 Fixed some mathtext parser problems relating to superscripts
6+
7+
2005-01-17 Fixed a yticklabel problem for colorbars under change of
8+
clim - JDH
9+
310
2005-01-17 Cleaned up Destroy handling in wx reducing memleak/fig from
411
approx 800k to approx 6k- JDH
512

‎TODO

Copy file name to clipboardExpand all lines: TODO
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,3 +629,12 @@ ZeroDivisionError: SeparableTransformation::eval_scalars yin interval is zero; c
629629
-- Jim's tick bug in non-interactive mode
630630

631631
-- more flexible tick placement.
632+
633+
-- fix horizontal colorbar axes resize if cax is None
634+
635+
-- mathtext layout bug
636+
637+
from pylab import *
638+
plot(range(10))
639+
title(r'$This\ is\ a\ test$')
640+
show()

‎examples/poormans_contour.py

Copy file name to clipboardExpand all lines: examples/poormans_contour.py
+5-6Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ def bivariate_normal(X, Y, sigmax=1.0, sigmay=1.0,
3131
X,Y = meshgrid(x, y)
3232
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
3333
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
34+
Z = Z2 - Z1 # difference of Gaussians
3435

36+
cmap = cm.get_cmap('jet', 10) # 10 discrete colors
3537

36-
cmap = ColormapJet(10) # 10 discrete contours
37-
im = imshow(Z2-Z1, cmap) # difference of Gaussians
38-
39-
# set the interpolation method: 'nearest', 'bilinear', 'bicubic' and much more
40-
im.set_interpolation('bilinear')
41-
38+
im = imshow(Z, cmap=cmap, interpolation='bilinear')
4239
axis('off')
40+
colorbar(tickfmt='%1.2f')
41+
clim(-.1, .1)
4342
#savefig('test')
4443
show()
4544

‎lib/matplotlib/_mathtext_data.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_mathtext_data.py
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
font data tables for truetype and afm computer modern fonts
33
"""
44

5+
# this dict maps symbol names to fontnames, glyphindex. To get the
6+
# glyph index from the character code, you have to use a reverse
7+
# dictionary grom font.get_charmaps, eg,
8+
"""
9+
from matplotlib.ft2font import FT2Font
10+
font = FT2Font('/usr/local/share/matplotlib/cmr10.ttf')
11+
codes = font.get_charmap().items()
12+
rd = dict([(charcode, glyphind) for glyphind,charcode in codes])
13+
items = rd.items()
14+
items.sort()
15+
16+
for charcode, glyphind in items:
17+
print charcode, glyphind
18+
"""
19+
520
latex_to_bakoma = {
621

722
r'\oint' : ('cmex10', 45),
@@ -123,6 +138,12 @@
123138
r'\rightbracket' : ('cmr10', 72),
124139
r']' : ('cmr10', 72),
125140

141+
142+
r'\circumflexaccent' : ('cmr10', 124), # for \hat
143+
r'\combiningbreve' : ('cmr10', 81), # for \breve
144+
r'\combiningoverline' : ('cmr10', 131), # for \bar
145+
146+
126147
r'\leftarrow' : ('cmsy10', 12),
127148
r'\uparrow' : ('cmsy10', 25),
128149
r'\downarrow' : ('cmsy10', 28),

‎lib/matplotlib/axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes.py
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,16 +1140,18 @@ def draw(self, renderer):
11401140
im = self.images[0]
11411141
im.draw(renderer)
11421142
elif len(self.images)>1:
1143+
11431144
# make a composite image blending alpha
11441145
# list of (_image.Image, ox, oy)
11451146

11461147
if not allequal([im.origin for im in self.images]):
11471148
raise ValueError('Composite images with different origins not supported')
11481149
else:
1149-
origin = self.images[0].origin
1150+
origin = self.images[0].origin
1151+
11501152
ims = [(im.make_image(renderer),0,0) for im in self.images if im.get_visible()]
11511153

1152-
1154+
11531155
im = _image.from_images(self.bbox.height(), self.bbox.width(), ims)
11541156
im.is_grayscale = False
11551157
l, b, w, h = self.bbox.get_bounds()

‎lib/matplotlib/cm.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cm.py
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,11 @@ def __init__(self, norm=None, cmap=None):
413413
self.norm = norm
414414
self.cmap = cmap
415415
self.observers = []
416-
416+
self.colorbar = None
417+
418+
def set_colorbar(self, im, ax):
419+
'set the colorbar image and axes associated with mappable'
420+
self.colorbar = im, ax
417421
def to_rgba(self, x, alpha=1.0):
418422
# assume normalized rgb, rgba
419423
if len(x.shape)>2: return x
@@ -428,6 +432,9 @@ def set_clim(self, vmin=None, vmax=None):
428432
'set the norm limits for image scaling'
429433
self.norm.vmin = vmin
430434
self.norm.vmax = vmax
435+
if self.colorbar is not None:
436+
im, ax = self.colorbar
437+
ax.set_ylim((vmin, vmax))
431438
self.changed()
432439

433440
def set_cmap(self, cmap):

‎lib/matplotlib/image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/image.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def make_image(self, flipy):
117117
else:
118118
raise RuntimeError('You must first set the image array or the image attribute')
119119

120+
120121
bg = colorConverter.to_rgba(self.axes.get_frame().get_facecolor(), 0)
121122
im.set_bg( *bg)
122123
im.is_grayscale = (self.cmap.name == "gray" and
@@ -151,6 +152,7 @@ def make_image(self, flipy):
151152

152153
l, b, widthDisplay, heightDisplay = self.axes.bbox.get_bounds()
153154

155+
154156
im.apply_translation(tx, ty)
155157
im.apply_scaling(sx, sy)
156158

@@ -172,6 +174,7 @@ def make_image(self, flipy):
172174
return im
173175

174176
def draw(self, renderer, *args, **kwargs):
177+
175178
if not self.get_visible(): return
176179
isUpper = self.origin=='upper'
177180
flipy = renderer.flipy()

‎lib/matplotlib/mathtext.py

Copy file name to clipboardExpand all lines: lib/matplotlib/mathtext.py
+53-16Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ def __init__(self, useSVG=False):
238238
[ (name, FT2Font(os.path.join(self.basepath, name) + '.ttf'))
239239
for name in self.fnames])
240240

241+
self.charmaps = dict(
242+
[ (name, self.fonts[name].get_charmap()) for name in self.fnames])
243+
241244
for font in self.fonts.values():
242245
font.clear()
243246
if useSVG:
@@ -261,7 +264,7 @@ def _get_info (self, font, sym, fontsize, dpi):
261264

262265
if latex_to_bakoma.has_key(sym):
263266
basename, num = latex_to_bakoma[sym]
264-
num = self.fonts[basename].get_charmap()[num]
267+
num = self.charmaps[basename][num]
265268
elif len(sym) == 1:
266269
num = ord(sym)
267270
else:
@@ -311,7 +314,7 @@ def render(self, ox, oy, font, sym, fontsize, dpi):
311314
basename = self.fontmap[font]
312315
if latex_to_bakoma.has_key(sym):
313316
basename, num = latex_to_bakoma[sym]
314-
num = self.fonts[basename].get_charmap()[num]
317+
num = self.charmaps[basename][num]
315318
elif len(sym) == 1:
316319
num = ord(sym)
317320
else:
@@ -342,6 +345,8 @@ def __init__(self):
342345
[ (name, FT2Font(os.path.join(self.basepath, name) + '.ttf'))
343346
for name in self.fnames])
344347

348+
self.charmaps = dict(
349+
[ (name, self.fonts[name].get_charmap()) for name in self.fnames])
345350
for font in self.fonts.values():
346351
font.clear()
347352

@@ -358,7 +363,7 @@ def _get_info (self, font, sym, fontsize, dpi):
358363
if latex_to_bakoma.has_key(sym):
359364
basename, num = latex_to_bakoma[sym]
360365
sym = self.fonts[basename].get_glyph_name(num)
361-
num = self.fonts[basename].get_charmap()[num]
366+
num = self.charmaps[basename][num]
362367
elif len(sym) == 1:
363368
num = ord(sym)
364369
else:
@@ -480,6 +485,7 @@ def set_origin(self, ox, oy):
480485
if loc=='above':
481486
nx = self.centerx() - element.width()/2.0
482487
ny = self.ymax() + self.pady()
488+
#print element, self.ymax(), element.height(), element.ymax(), element.ymin(), ny
483489
elif loc=='below':
484490
nx = self.centerx() - element.width()/2.0
485491
ny = self.ymin() - self.pady() - element.height()
@@ -529,7 +535,7 @@ def set_scale(self, scale):
529535
self._scale = scale
530536

531537
def centerx(self):
532-
return self.ox + self.advance()/2.0
538+
return 0.5 * (self.xmax() + self.xmin() )
533539

534540
def centery(self):
535541
return 0.5 * (self.ymax() + self.ymin() )
@@ -539,18 +545,22 @@ def __repr__(self):
539545

540546
class SpaceElement(Element):
541547
'blank horizontal space'
542-
def __init__(self, space):
543-
'space is the amount of blank space in fraction of fontsize'
548+
def __init__(self, space, height=0):
549+
"""
550+
space is the amount of blank space in fraction of fontsize
551+
height is the height of the space in fraction of fontsize
552+
"""
544553
Element.__init__(self)
545554
self.space = space
555+
self._height = height
546556

547557
def advance(self):
548558
'get the horiz advance'
549559
return self.dpi/72.0*self.space*self.fontsize
550560

551561
def height(self):
552562
'get the element height: ymax-ymin'
553-
return 0
563+
return self._height*self.dpi/72.0*self.fontsize
554564

555565
def width(self):
556566
'get the element width: xmax-xmin'
@@ -570,7 +580,7 @@ def ymin(self):
570580

571581
def ymax(self):
572582
'get the max ink in y'
573-
return self.oy
583+
return self.oy + self.height()
574584

575585
def set_font(self, f):
576586
# space doesn't care about font, only size
@@ -772,7 +782,23 @@ def composite(self, s, loc, toks):
772782
self.symbols.append(sym1)
773783

774784
return loc, [sym0]
775-
785+
786+
def accent(self, s, loc, toks):
787+
788+
assert(len(toks)==1)
789+
accent, sym = toks[0]
790+
791+
d = {
792+
r'\hat' : r'\circumflexaccent',
793+
r'\breve' : r'\combiningbreve',
794+
r'\bar' : r'\combiningoverline',
795+
}
796+
above = SymbolElement(d[accent])
797+
sym.neighbors['above'] = above
798+
sym.set_pady(1)
799+
self.symbols.append(above)
800+
return loc, [sym]
801+
776802
def group(self, s, loc, toks):
777803
assert(len(toks)==1)
778804
#print 'grp', toks
@@ -790,7 +816,11 @@ def font(self, s, loc, toks):
790816
def subscript(self, s, loc, toks):
791817
assert(len(toks)==1)
792818
#print 'subsup', toks
793-
prev, under, next = toks[0]
819+
if len(toks[0])==2:
820+
under, next = toks[0]
821+
prev = SpaceElement(0)
822+
else:
823+
prev, under, next = toks[0]
794824

795825
if self.is_overunder(prev):
796826
prev.neighbors['below'] = next
@@ -805,8 +835,11 @@ def is_overunder(self, prev):
805835
def superscript(self, s, loc, toks):
806836
assert(len(toks)==1)
807837
#print 'subsup', toks
808-
prev, under, next = toks[0]
809-
838+
if len(toks[0])==2:
839+
under, next = toks[0]
840+
prev = SpaceElement(0,0.6)
841+
else:
842+
prev, under, next = toks[0]
810843
if self.is_overunder(prev):
811844
prev.neighbors['above'] = next
812845
else:
@@ -866,6 +899,10 @@ def subsuperscript(self, s, loc, toks):
866899
#~ composite = over | under
867900
overUnder = over | under
868901

902+
accent = Literal('hat') | Literal('check') | Literal('dot') | \
903+
Literal('breve') | Literal('acute') | Literal('ddot') | \
904+
Literal('grave') | Literal('tilde') | Literal('bar') | Literal('vec')
905+
869906

870907

871908
number = Combine(Word(nums) + Optional(Literal('.')) + Optional( Word(nums) ))
@@ -904,20 +941,20 @@ def subsuperscript(self, s, loc, toks):
904941
#~ composite = Group( Combine(bslash + composite) + group + group).setParseAction(handler.composite).setName("composite")
905942
composite = Group( Combine(bslash + overUnder) + group + group).setParseAction(handler.composite).setName("composite")
906943

907-
944+
accent = Group( Combine(bslash + accent) + group).setParseAction(handler.accent).setName("accent")
908945

909946
#~ symgroup = symbol ^ group
910947
symgroup = symbol | group
911948

912-
subscript << Group( symgroup + Literal('_') + symgroup )
913-
superscript << Group( symgroup + Literal('^') + symgroup )
949+
subscript << Group( Optional(symgroup) + Literal('_') + symgroup )
950+
superscript << Group( Optional(symgroup) + Literal('^') + symgroup )
914951
subsuperscript << Group( symgroup + Literal('_') + symgroup + Literal('^') + symgroup )
915952

916953

917954
font = Group( Combine(bslash + fontname) + group).setParseAction(handler.font).setName("font")
918955

919956
expression = OneOrMore(
920-
space ^ font ^ symbol ^ subscript ^ superscript ^ subsuperscript ^ group ^ composite ).setParseAction(handler.expression).setName("expression")
957+
space ^ font ^ accent ^ symbol ^ subscript ^ superscript ^ subsuperscript ^ group ^ composite ).setParseAction(handler.expression).setName("expression")
921958
#~ expression = OneOrMore(
922959
#~ group | composite | space | font | subsuperscript | subscript | superscript | symbol ).setParseAction(handler.expression).setName("expression")
923960

‎lib/matplotlib/pylab.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pylab.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,13 +615,14 @@ def colorbar(tickfmt='%1.1f', cax=None, orientation='vertical'):
615615

616616
if orientation=='vertical':
617617
C = transpose(C)
618+
618619
coll = cax.imshow(C,
619620
interpolation='nearest',
620621
origin='lower',
621622
cmap=cmap, norm=norm,
622623
extent=(0, 1, cmin, cmax))
623624
mappable.add_observer(coll)
624-
625+
mappable.set_colorbar(coll, cax)
625626
if orientation=='vertical':
626627
cax.set_xticks([])
627628
cax.yaxis.tick_right()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.