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

Skip to content

Commit c25f882

Browse files
committed
fixed small raster problem with dvipng
svn path=/trunk/matplotlib/; revision=1361
1 parent 97e19c3 commit c25f882

3 files changed

Lines changed: 35 additions & 25 deletions

File tree

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-05-21 Fixed raster problem for small rasters with dvipng -- looks
4+
like it was a premultipled alpha problem - JDH
5+
36
2005-05-20 Added linewidth and faceted kwarg to scatter to control
47
edgewidth and color. Also added autolegend patch to
58
inspect line segments.

examples/tex_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
xlabel('time (s)')
1010
ylabel('voltage (mV)')
11-
title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{-i\pi}}{2^n}$!",
12-
color='red', fontsize=20)
11+
title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",
12+
fontsize=20)
1313
grid(True)
1414
savefig('tex_demo')
1515
show()

lib/matplotlib/texmanager.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from matplotlib import get_home, get_data_path
1313
from matplotlib._image import readpng, fromarray
1414
from matplotlib.numerix import ravel, where, array, \
15-
zeros, Float, absolute, nonzero, put, putmask
15+
zeros, Float, absolute, nonzero, sqrt
1616
class TexManager:
1717
"""
1818
Convert strings to dvi files using TeX, caching the results to a
@@ -21,13 +21,15 @@ class TexManager:
2121
path = get_home()
2222
if path is None: path = get_data_path()
2323
texcache = os.path.join(path, '.tex.cache')
24+
2425

2526
def __init__(self):
2627
if not os.path.isdir(self.texcache):
2728
os.mkdir(self.texcache)
2829
self.imaged = {}
2930
self.postscriptd = {}
3031
self.pscnt = 0
32+
self.dvipngVersion = None
3133

3234
def make_dvi(self, tex):
3335
prefix = self.get_prefix(tex)
@@ -215,31 +217,36 @@ def get_image(self, tex, fontsize=10, dpi=80, rgb=(0,0,0)):
215217

216218

217219
if im is None:
218-
# skip cacheing while debugging
220+
# force=True to skip cacheing while debugging
219221
pngfile = self.make_png(tex, dpi, force=False)
220222
X = readpng(pngfile)
221-
# To compare my results with the result of using dvipng's,
222-
# change this to 'if 0:' and uncomment the third "command"
223-
# variable in make_png. The black text for the tick
224-
# labels on the gray background look better with the
225-
# dvipng rendering, so I must be making some error in how
226-
# I try and recover the alpha information
227-
if 1:
228-
alpha = 1-X[:,:,0]
229-
#visible = alpha>0
230-
#print 'min/max', min(ravel(alpha)), max(ravel(alpha))
231-
Z = zeros(X.shape, Float)
232-
Z[:,:,0] = r
233-
Z[:,:,1] = g
234-
Z[:,:,2] = b
235-
Z[:,:,3] = alpha
236-
im = fromarray(Z, 1)
223+
224+
vers = self.get_dvipng_version()
225+
if vers<'1.6':
226+
alpha = sqrt(1-X[:,:,0])
237227
else:
238-
alpha = X[:,:,-1]
239-
from matplotlib.mlab import prctile
240-
print 'ptile', prctile(ravel(alpha))
241-
im = fromarray(X, 1)
228+
# 1.6 has the alpha channel right
229+
alpha = sqrt(X[:,:,-1])
230+
231+
#from matplotlib.mlab import prctile
232+
#print 'ptile', prctile(ravel(X[:,:,0])), prctile(ravel(X[:,:,-1]))
233+
234+
Z = zeros(X.shape, Float)
235+
Z[:,:,0] = r
236+
Z[:,:,1] = g
237+
Z[:,:,2] = b
238+
Z[:,:,3] = alpha
239+
im = fromarray(Z, 1)
242240

243241
self.imaged[key] = im
244242
return im
245-
243+
244+
def get_dvipng_version(self):
245+
if self.dvipngVersion is not None: return self.dvipngVersion
246+
sin, sout = os.popen2('dvipng --version')
247+
for line in sout.readlines():
248+
if line.startswith('dvipng '):
249+
self.dvipngVersion = line.split()[-1]
250+
return self.dvipngVersion
251+
raise RuntimeError('Could not obtain dvipng version')
252+

0 commit comments

Comments
 (0)