Skip to content

Commit 1fff01d

Browse files
committed
added caching for tex/agg
svn path=/trunk/matplotlib/; revision=1429
1 parent 1eba308 commit 1fff01d

File tree

6 files changed

+49
-24
lines changed

6 files changed

+49
-24
lines changed

.matplotlibrc

+3-2
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,15 @@ font.sans-serif : Lucida Grande, Verdana, Geneva, Lucida, Bitstream Vera San
116116
font.cursive : Apple Chancery, Textile, Zapf Chancery, Sand, cursive
117117
font.fantasy : Comic Sans MS, Chicago, Charcoal, Impact, Western, fantasy
118118
font.monospace : Andale Mono, Bitstream Vera Sans Mono, Nimbus Mono L, Courier New, Courier, Fixed, Terminal, monospace
119-
font.latex.package : type1cm # This must be an available LaTeX font package, like 'times' or 'pslatex'
119+
font.latex.package : type1cm # This must be an available LaTeX font
120+
#package, like 'times' or 'pslatex' ; only applies if text.usetex is set
120121

121122
### TEXT
122123
# text properties used by text.Text. See
123124
# http://matplotlib.sourceforge.net/matplotlib.text.html for more
124125
# information on text properties
125126
text.color : black
126-
text.usetex : False # use tex for all text handling. See http://matplotlib.sf.net/matplotlib.texmanager.html
127+
text.usetex : False # use tex/latex for all text handling. See http://matplotlib.sf.net/matplotlib.texmanager.html
127128
text.tex.engine : latex # tex is faster, but latex is required to use special font packages
128129

129130
### AXES

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ clean:
1515
rm -f *.png *.ps *.eps *.svg *.jpg
1616
find . -name "_tmp*.py" | xargs rm -f;\
1717
find . \( -name "*~" -o -name "*.pyc" \) | xargs rm -f;\
18-
find examples \( -name "*.svg" -o -name "*.png" -o -name "*.ps" -o -name "*.eps" -o -name "*.tar" -name "*.gz" \) | xargs rm -f
18+
find examples \( -name "*.svg" -o -name "*.png" -o -name "*.ps" -o -name "*.eps" -o -name "*.tar" -o -name "*.gz" -o -name "*.log" -o -name "*.aux" -o -name "*.tex" \) | xargs rm -f
1919
find unit \( -name "*.png" -o -name "*.ps" -o -name "*.eps" \) | xargs rm -f
2020
find . \( -name "#*" -o -name ".#*" -o -name ".*~" -o -name "*~" \) | xargs rm -f
2121

examples/tex_demo.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
#!/usr/bin/env python
2-
from pylab import *
2+
"""
3+
You can use TeX to render all of your matplotlib text if the rc
4+
parameter text.usetex is set. This works currently on the agg and ps
5+
backends, and requires that you have tex and the other dependencies
6+
described at http://matplotlib.sf.net/matplotlib.texmanager.html
7+
properly installed on your system. The first time you run a script
8+
you will see a lot of output from tex and associated tools. The next
9+
time, the run may be silent, as a lot of the information is cached in
10+
~/.tex.cache
11+
12+
"""
13+
from matplotlib import rc
14+
from matplotlib.numerix import arange, cos, pi
15+
from pylab import figure, axes, plot, xlabel, ylabel, title, \
16+
grid, savefig, show
17+
18+
319
rc('text', usetex=True)
420
figure(1)
521
ax = axes([0.1, 0.1, 0.8, 0.7])

lib/matplotlib/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
"""
143143
from __future__ import generators
144144

145-
__version__ = '0.81alpha'
145+
__version__ = '0.81rc1'
146146
__revision__ = '$Revision$'
147147
__date__ = '$Date$'
148148

lib/matplotlib/backends/backend_agg.py

+25-18
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def __init__(self, width, height, dpi):
123123
self.cache = self._renderer.cache
124124
self.blit = self._renderer.blit
125125
self.texmanager = TexManager()
126+
self.texd = {} # a cache of tex image rasters
126127
self.bbox = lbwh_to_bbox(0,0, self.width, self.height)
127128

128129

@@ -254,27 +255,33 @@ def draw_tex(self, gc, x, y, s, prop, angle):
254255

255256
flip = angle==90
256257
w,h = self.get_text_width_height(s, prop, 'TeX', rgb)
257-
258-
Z = self.texmanager.get_rgba(s, size, dpi, rgb)
259258
if flip:
260259
w,h = h,w
261260
x -= w
262-
r = Z[:,:,0]
263-
g = Z[:,:,1]
264-
b = Z[:,:,2]
265-
a = Z[:,:,3]
266-
m,n,tmp = Z.shape
267-
268-
def func(x):
269-
return transpose(fliplr(x))
270-
271-
Z = zeros((n,m,4), typecode=Float)
272-
Z[:,:,0] = func(r)
273-
Z[:,:,1] = func(g)
274-
Z[:,:,2] = func(b)
275-
Z[:,:,3] = func(a)
276-
277-
im = fromarray(Z, 1)
261+
262+
key = s, size, dpi, rgb
263+
im = self.texd.get(key)
264+
265+
if im is None:
266+
Z = self.texmanager.get_rgba(s, size, dpi, rgb)
267+
if flip:
268+
r = Z[:,:,0]
269+
g = Z[:,:,1]
270+
b = Z[:,:,2]
271+
a = Z[:,:,3]
272+
m,n,tmp = Z.shape
273+
274+
def func(x):
275+
return transpose(fliplr(x))
276+
277+
Z = zeros((n,m,4), typecode=Float)
278+
Z[:,:,0] = func(r)
279+
Z[:,:,1] = func(g)
280+
Z[:,:,2] = func(b)
281+
Z[:,:,3] = func(a)
282+
im = fromarray(Z, 1)
283+
self.texd[key] = im
284+
278285
self.draw_image(x, y-h, im, 'upper', self.bbox)
279286

280287
def get_canvas_width_height(self):

lib/matplotlib/texmanager.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
1111
*Agg backends: dvipng
1212
13-
PS backend: latex w/ psfrag, dvips
13+
PS backend: latex w/ psfrag, dvips, and Ghostscript 8.51
14+
(older versions do not work properly)
1415
1516
Backends:
1617

0 commit comments

Comments
 (0)