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

Skip to content

Commit c6d5085

Browse files
committed
added switch to use latex or tex
svn path=/trunk/matplotlib/; revision=1363
1 parent f1c5597 commit c6d5085

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

examples/tex_demo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
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}$!",
11+
##title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",
12+
## fontsize=20)
13+
title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty{-e^{i\pi} \over 2^n}$!",
1214
fontsize=20)
1315
grid(True)
1416
savefig('tex_demo')

lib/matplotlib/backends/backend_latex.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ def get_text_width_height(self, s, prop, ismath):
2121
get the width and height in display coords of the string s
2222
with FontPropertry prop
2323
"""
24+
fontsize = prop.get_size_in_points()
2425
l,b,r,t = self.texmanager.get_ps_bbox(s)
25-
w = r-l
26-
h = t-b
26+
w = (r-l)#*fontsize/10.
27+
h = (t-b)#*fontsize/10.
2728
#print s, w, h
2829
return w, h
2930

@@ -33,7 +34,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath):
3334
"""
3435
w, h = self.get_text_width_height(s, prop, ismath)
3536
fontsize = prop.get_size_in_points()
36-
corr = w/2*(fontsize-10)/10
37+
corr = 0#w/2*(fontsize-10)/10
3738
pos = _nums_to_str(x-corr, y)
3839
thetext = 'psmarker%d' % self.textcnt
3940
setcolor = '%1.3f %1.3f %1.3f setrgbcolor' % gc.get_rgb()

lib/matplotlib/texmanager.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,24 @@ def make_dvi(self, tex):
3939

4040
logfile = prefix + '.log'
4141
fh = file(fname, 'w')
42-
## fh.write(tex + '\n\\nopagenumbers\n\\bye\n')
43-
s = r"""\documentclass{article}
42+
if True: #use latex
43+
s = r"""\documentclass{article}
4444
\pagestyle{empty}
4545
\begin{document}
4646
%s
47-
\end{document}""" % tex
48-
fh.write(s)
49-
fh.close()
50-
## command = 'tex %s'%fname
51-
command = 'latex %s'%fname
47+
\end{document}
48+
""" % tex
49+
fh.write(s)
50+
fh.close()
51+
command = 'latex %s'%fname
52+
else:
53+
s = r"""\nopagenumbers
54+
%s
55+
\bye
56+
""" % tex
57+
fh.write(s)
58+
fh.close()
59+
command = 'tex %s'%fname
5260
if not os.path.exists(dvifile):
5361
#sin, sout = os.popen2(command)
5462
#sout.close()

0 commit comments

Comments
 (0)