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

Skip to content

Commit 27b60a0

Browse files
committed
Removed mathtext2. Fix horizontal centering in mathtext. Put all
mathtext_examples on one plot. svn path=/trunk/matplotlib/; revision=3676
1 parent 1537da3 commit 27b60a0

9 files changed

Lines changed: 68 additions & 1196 deletions

File tree

CHANGELOG

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
2007-08-06 Removed mathtext2
2+
3+
2007-07-31 Refactoring of distutils scripts.
4+
- Will not fail on the entire build if an optional Python
5+
package (e.g. Tkinter) is installed but its development
6+
headers are not (e.g. tk-devel). Instead, it will
7+
continue to build all other extensions.
8+
- Provide an overview at the top of the output to display
9+
what dependencies and their versions were found, and (by
10+
extension) what will be built.
11+
- Use pkg-config, when available, to find freetype2, since
12+
this was broken on Mac OS-X when using MacPorts in a non-
13+
standard location.
14+
115
2007-07-30 Reorganized configuration code to work with traited config
216
objects. The new config system is located in the
317
matplotlib.config package, but it is disabled by default.

examples/mathtext2_demo.py

Lines changed: 0 additions & 89 deletions
This file was deleted.

examples/mathtext_examples.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
r'$x_y^2$',
2121
r'$\prod_{i=\alpha_{i+1}}^\infty$',
2222
r'$x = \frac{x+\frac{5}{2}}{\frac{y+3}{8}}$',
23-
r'$dz/dt \/ = \/ \gamma x^2 \/ + \/ {\rm sin}(2\pi y+\phi)$',
24-
r'Foo: $\alpha_{i+1}^j \/ = \/ {\rm sin}(2\pi f_j t_i) e^{-5 t_i/\tau}$',
23+
r'$dz/dt = \gamma x^2 + {\rm sin}(2\pi y+\phi)$',
24+
r'Foo: $\alpha_{i+1}^j = {\rm sin}(2\pi f_j t_i) e^{-5 t_i/\tau}$',
2525
r'$\mathcal{R}\prod_{i=\alpha_{i+1}}^\infty a_i \sin(2 \pi f x_i)$',
2626
# r'$\bigodot \bigoplus {\sf R} a_i{\rm sin}(2 \pi f x_i)$',
2727
r'Variable $i$ is good',
@@ -33,31 +33,36 @@
3333
r"$\gamma = \frac{x=\frac{6}{8}}{y} \delta$",
3434
r'$\limsup_{x\to\infty}$',
3535
r'$\oint^\infty_0$',
36-
r"$f'$",
36+
r"$f^'$",
3737
r'$\frac{x_2888}{y}$',
3838
r"$\sqrt[3]{\frac{X_2}{Y}}=5$",
3939
r"$\sqrt[5x\pi]{\prod^\frac{x}{2\pi^2}_\infty}$",
4040
r"$\sqrt[3]{x}=5$",
4141
r'$\frac{X}{\frac{X}{Y}}$',
4242
# From UTR #25
4343
r"$W^{3\beta}_{\delta_1 \rho_1 \sigma_2} = U^{3\beta}_{\delta_1 \rho_1} + \frac{1}{8 \pi 2} \int^{\alpha_2}_{\alpha_2} d \alpha^\prime_2 \left[\frac{ U^{2\beta}_{\delta_1 \rho_1} - \alpha^\prime_2U^{1\beta}_{\rho_1 \sigma_2} }{U^{0\beta}_{\rho_1 \sigma_2}}\right]$",
44-
r'$\mathcal{H} = \int d \tau (\epsilon E^2 + \mu H^2)$',
45-
r'$\widehat{abc}\widetilde{def}$'
44+
r'$\mathcal{H} = \int d \tau \left(\epsilon E^2 + \mu H^2\right)$',
45+
r'$\widehat{abc}\widetilde{def}$',
46+
r'$\Gamma \Delta \Theta \Lambda \Xi \Pi \Sigma \Upsilon \Phi \Psi \Omega$',
47+
r'$\alpha \beta \gamma \delta \epsilon \zeta \eta \theta \iota \lambda \mu \nu \xi \pi \kappa \rho \sigma \tau \upsilon \phi \chi \psi$'
4648
]
4749

4850
from pylab import *
4951

5052
def doall():
51-
for i, s in enumerate(stests):
53+
tests = stests
54+
55+
figure(figsize=(8, (len(tests) * 1) + 2))
56+
plot([0, 0], 'r')
57+
grid(False)
58+
axis([0, 3, -len(tests), 0])
59+
yticks(arange(len(tests)) * -1)
60+
for i, s in enumerate(tests):
5261
print "%02d: %s" % (i, s)
53-
plot([0,0,3], 'r')
54-
x = arange(0.0, 3.0, 0.1)
55-
56-
grid(True)
57-
text(0.1, 1.6, s, fontsize=20, markup="tex")
62+
text(0.1, -i, s, fontsize=20, markup="tex")
5863

59-
savefig('mathtext_example%02d' % i)
60-
figure()
64+
savefig('mathtext_example')
65+
figure()
6166

6267
if '--latex' in sys.argv:
6368
fd = open("mathtext_examples.ltx", "w")

lib/matplotlib/config/mplconfig.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,13 @@ class font(TConfig):
153153
class text(TConfig):
154154
color = T.Trait('black',mplT.ColorHandler())
155155
usetex = T.false
156+
markup = T.Trait('plain', 'tex')
156157

157158
class latex(TConfig):
158159
unicode = T.false
159160
preamble = T.ListStr([])
160161
dvipnghack = T.false
161162

162-
class math(TConfig):
163-
mathtext2 = T.false
164-
rm = T.Trait('cmr10.ttf')
165-
it = T.Trait('cmmi10.ttf')
166-
tt = T.Trait('cmtt10.ttf')
167-
mit = T.Trait('cmmi10.ttf')
168-
cal = T.Trait('cmsy10.ttf')
169-
nonascii = T.Trait('cmex10.ttf')
170-
171163
class axes(TConfig):
172164
hold = T.Trait(True, mplT.BoolHandler())
173165
facecolor = T.Trait('white', mplT.ColorHandler())
@@ -336,6 +328,7 @@ def __init__(self, tconfig):
336328
'text.latex.unicode' : (self.tconfig.text.latex, 'unicode'),
337329
'text.latex.preamble' : (self.tconfig.text.latex, 'preamble'),
338330
'text.dvipnghack' : (self.tconfig.text.latex, 'dvipnghack'),
331+
'text.markup' : (self.tconfig.text.markup, 'markup'),
339332

340333
'image.aspect' : (self.tconfig.image, 'aspect'),
341334
'image.interpolation' : (self.tconfig.image, 'interpolation'),
@@ -429,14 +422,6 @@ def __init__(self, tconfig):
429422
'svg.image_noscale' : (self.tconfig.backend.svg, 'image_noscale'),
430423
'svg.embed_char_paths' : (self.tconfig.backend.svg, 'embed_chars'),
431424

432-
# mathtext settings
433-
'mathtext.mathtext2' : (self.tconfig.text.math, 'mathtext2'),
434-
'mathtext.rm' : (self.tconfig.text.math, 'rm'),
435-
'mathtext.it' : (self.tconfig.text.math, 'it'),
436-
'mathtext.tt' : (self.tconfig.text.math, 'tt'),
437-
'mathtext.mit' : (self.tconfig.text.math, 'mit'),
438-
'mathtext.cal' : (self.tconfig.text.math, 'cal'),
439-
'mathtext.nonascii' : (self.tconfig.text.math, 'nonascii'),
440425
}
441426

442427
def __setitem__(self, key, val):

lib/matplotlib/config/rcsetup.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -448,16 +448,6 @@ def __call__(self, s):
448448
'svg.embed_char_paths' : [False, validate_bool], # True to save
449449
#all characters as paths in the SVG
450450

451-
# mathtext settings
452-
'mathtext.mathtext2' : [False, validate_bool], # Needed to enable Unicode
453-
# fonts used by mathtext. These ship with matplotlib
454-
'mathtext.rm' : ['cmr10.ttf', str], # Roman (normal)
455-
'mathtext.it' : ['cmmi10.ttf', str], # Italic
456-
'mathtext.tt' : ['cmtt10.ttf', str], # Typewriter (monospaced)
457-
'mathtext.mit' : ['cmmi10.ttf', str], # Math italic
458-
'mathtext.cal' : ['cmsy10.ttf', str], # Caligraphic
459-
'mathtext.nonascii' : ['cmex10.ttf', str], # All other nonascii fonts
460-
461451
}
462452

463453
if __name__ == '__main__':

lib/matplotlib/mathtext.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def set_canvas_size(self, w, h):
246246

247247
def render_glyph(self, ox, oy, info):
248248
info.font.draw_glyph_to_bitmap(
249-
int(ox), int(oy - info.metrics.ymax), info.glyph)
249+
ox, oy - info.metrics.ymax, info.glyph)
250250

251251
def render_rect_filled(self, x1, y1, x2, y2):
252252
font = self.fonts_object.get_fonts()[0]
@@ -297,7 +297,7 @@ def __init__(self):
297297
def render_glyph(self, ox, oy, info):
298298
filename = info.font.fname
299299
oy = self.height - oy + info.offset
300-
300+
301301
self.pswriter.append(('glyph', ox, oy, filename, info.fontsize, info.num))
302302

303303
def render_rect_filled(self, x1, y1, x2, y2):
@@ -865,15 +865,15 @@ def get_underline_thickness(self, font, fontsize, dpi):
865865
# get any smaller
866866
NUM_SIZE_LEVELS = 4
867867
# Percentage of x-height of additional horiz. space after sub/superscripts
868-
SCRIPT_SPACE = 0.3
868+
SCRIPT_SPACE = 0.2
869869
# Percentage of x-height that sub/superscripts drop below the baseline
870870
SUBDROP = 0.3
871871
# Percentage of x-height that superscripts drop below the baseline
872872
SUP1 = 0.7
873873
# Percentage of x-height that subscripts drop below the baseline
874874
SUB1 = 0.0
875875
# Percentage of x-height that superscripts are offset relative to the subscript
876-
DELTA = 0.25
876+
DELTA = 0.18
877877

878878
class MathTextWarning(Warning):
879879
pass
@@ -1101,19 +1101,20 @@ def kern(self):
11011101
list in the correct way."""
11021102
new_children = []
11031103
num_children = len(self.children)
1104-
for i in range(num_children):
1105-
elem = self.children[i]
1106-
if i < num_children - 1:
1107-
next = self.children[i + 1]
1108-
else:
1109-
next = None
1104+
if num_children:
1105+
for i in range(num_children):
1106+
elem = self.children[i]
1107+
if i < num_children - 1:
1108+
next = self.children[i + 1]
1109+
else:
1110+
next = None
11101111

1111-
new_children.append(elem)
1112-
kerning_distance = elem.get_kerning(next)
1113-
if kerning_distance != 0.:
1114-
kern = Kern(kerning_distance)
1115-
new_children.append(kern)
1116-
self.children = new_children
1112+
new_children.append(elem)
1113+
kerning_distance = elem.get_kerning(next)
1114+
if kerning_distance != 0.:
1115+
kern = Kern(kerning_distance)
1116+
new_children.append(kern)
1117+
self.children = new_children
11171118

11181119
def hpack(self, w=0., m='additional'):
11191120
"""The main duty of hpack is to compute the dimensions of the
@@ -1372,9 +1373,15 @@ def __init__(self):
13721373
class HCentered(Hlist):
13731374
"""A convenience class to create an Hlist whose contents are centered
13741375
within its enclosing box."""
1375-
def __init__(self, elements):
1376+
def __init__(self, elements, is_accent = False):
1377+
self.is_accent = is_accent
13761378
Hlist.__init__(self, [SsGlue()] + elements + [SsGlue()])
13771379

1380+
def kern(self):
1381+
Hlist.kern(self)
1382+
if not self.is_accent and isinstance(self.children[-2], Kern):
1383+
self.children = self.children[:-2] + [SsGlue()]
1384+
13781385
class VCentered(Hlist):
13791386
"""A convenience class to create an Vlist whose contents are centered
13801387
within its enclosing box."""
@@ -1982,7 +1989,7 @@ def accent(self, s, loc, toks):
19821989
else:
19831990
accent = Accent(self._accent_map[accent], state)
19841991
shift_amount = accent._metrics.xmin
1985-
centered = HCentered([accent])
1992+
centered = HCentered([accent], is_accent=True)
19861993
centered.hpack(sym.width, 'exactly')
19871994
centered.shift_amount = shift_amount
19881995
return Vlist([

0 commit comments

Comments
 (0)