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

Skip to content

Commit 07794dc

Browse files
committed
In text, linespace-related changes
svn path=/trunk/matplotlib/; revision=3504
1 parent 30a5d33 commit 07794dc

5 files changed

Lines changed: 33 additions & 32 deletions

File tree

API_CHANGES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Text creation commands have a new default linespacing and
2+
a new linespacing kwarg, which is a multiple of the maximum
3+
vertical extent of a line of ordinary text. The default is
4+
1.2; linespacing=2 would be like ordinary double spacing, for
5+
example.
6+
17
Changed default kwarg in colors.Normalize.__init__ to clip=False;
28
clipping silently defeats the purpose of the special over, under,
39
and bad values in the colormap, thereby leading to unexpected

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2007-07-11 Added linespacing kwarg to text.Text - EF
2+
13
2007-07-11 Added code to store font paths in SVG files. - MGD
24

35
2007-07-10 Store subset of TTF font as a Type 3 font in PDF files. - MGD

lib/matplotlib/axes.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ class Axes(Artist):
460460
scaled = {IDENTITY : 'linear',
461461
LOG10 : 'log',
462462
}
463-
463+
464464
def __str__(self):
465465
return "Axes(%g,%g;%gx%g)"%(self._position[0].get(),self._position[1].get(),
466466
self._position[2].get(),self._position[3].get())
@@ -1955,11 +1955,11 @@ def get_children(self):
19551955

19561956
def contains(self,mouseevent):
19571957
"""Test whether the mouse event occured in the axes.
1958-
1958+
19591959
Returns T/F, {}
19601960
"""
19611961
if callable(self._contains): return self._contains(self,mouseevent)
1962-
1962+
19631963
x,y = self.axes.transAxes.inverse_xy_tup((mouseevent.x,mouseevent.y))
19641964
inside = x>=0 and x<=1 and y>=0 and y<=1
19651965
return inside,{}
@@ -5313,7 +5313,7 @@ class Subplot(SubplotBase, Axes):
53135313
"""
53145314
def __str__(self):
53155315
return "Subplot(%g,%g)"%(self.bottom.get(),self.left.get())
5316-
5316+
53175317
def __init__(self, fig, *args, **kwargs):
53185318
"""
53195319
See Axes base class documentation for args and kwargs
@@ -5380,11 +5380,11 @@ def _set_lim_and_transforms(self):
53805380

53815381
def contains(self,mouseevent):
53825382
"""Test whether the mouse event occured in the axes.
5383-
5383+
53845384
Returns T/F, {}
53855385
"""
53865386
if callable(self._contains): return self._contains(self,mouseevent)
5387-
5387+
53885388
x,y = self.axes.transAxes.inverse_xy_tup((mouseevent.x,mouseevent.y))
53895389
#print "Polar: x,y = ",x,y
53905390
inside = (x-0.5)**2 + (y-0.5)**2 <= 0.25
@@ -5561,7 +5561,7 @@ def set_rgrids(self, radii, labels=None, angle=22.5, rpad=0.05, **kwargs):
55615561
rmax = self.get_rmax()
55625562
for r in radii:
55635563
r = ones(self.RESOLUTION)*r
5564-
line = Line2D(theta, r, linestyle=ls, color=color, linewidth=lw,
5564+
line = Line2D(theta, r, linestyle=ls, color=color, linewidth=lw,
55655565
figure=self.figure)
55665566
#line = Line2D(nx.mlab.rand(len(theta)), nx.mlab.rand(len(theta)),
55675567
# linestyle=ls, color=color, linewidth=lw, figure=self.figure)

lib/matplotlib/pylab.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ def plotfile(fname, cols=(0,), plotfuncs=None,
15421542
Example usage:
15431543
15441544
# plot the 2nd and 4th column against the 1st in two subplots
1545-
plotfile(fname, (0,1,3))
1545+
plotfile(fname, (0,1,3))
15461546
15471547
# plot using column names; specify an alternate plot type for volume
15481548
plotfile(fname, ('date', 'volume', 'adj_close'), plotfuncs={'volume': 'semilogy'})
@@ -1561,7 +1561,7 @@ def getname_val(identifier):
15611561
'return the name and column data for identifier'
15621562
if cbook.is_string_like(identifier):
15631563
return identifier, r[identifier]
1564-
elif cbook.is_numlike(identifier):
1564+
elif cbook.is_numlike(identifier):
15651565
name = r.dtype.names[int(identifier)]
15661566
return name, r[name]
15671567
else:
@@ -1590,7 +1590,7 @@ def getname_val(identifier):
15901590

15911591
funcname = plotfuncs.get(cols[i], 'plot')
15921592
func = getattr(ax, funcname)
1593-
1593+
15941594
func(x, y, **kwargs)
15951595
ax.set_ylabel(yname)
15961596
if ax.is_last_row():
@@ -1601,7 +1601,7 @@ def getname_val(identifier):
16011601

16021602
if xname=='date':
16031603
fig.autofmt_xdate()
1604-
1604+
16051605
draw_if_interactive()
16061606

16071607
### Deprecated functions:

lib/matplotlib/text.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def __init__(self,
145145
multialignment=None,
146146
fontproperties=None, # defaults to FontProperties()
147147
rotation=None,
148-
linespacing=1.2,
148+
linespacing=None,
149149
**kwargs
150150
):
151151
"""
@@ -169,6 +169,8 @@ def __init__(self,
169169
self._fontproperties = fontproperties
170170
self._bbox = None
171171
self._renderer = None
172+
if linespacing is None:
173+
linespacing = 1.2 # Maybe use rcParam later.
172174
self._linespacing = linespacing
173175
self.update(kwargs)
174176
#self.set_bbox(dict(pad=0))
@@ -205,20 +207,7 @@ def _get_multialignment(self):
205207

206208
def get_rotation(self):
207209
'return the text angle as float'
208-
#return 0
209-
210-
# if self._rotation in ('horizontal', None):
211-
# angle = 0.
212-
# elif self._rotation == 'vertical':
213-
# angle = 90.
214-
# else:
215-
# angle = float(self._rotation)
216-
# return angle%360
217-
218-
# Since the get_rotation logic was extracted
219-
# into a function for TextWithDash, this
220-
# method could now read as follows.
221-
return get_rotation(self._rotation)
210+
return get_rotation(self._rotation) # string_or_number -> number
222211

223212
def update_from(self, other):
224213
'Copy properties from other to self'
@@ -251,18 +240,18 @@ def _get_layout(self, renderer):
251240
lines = self._text.split('\n')
252241

253242
whs = []
254-
# Find full vertical extent, including ascenders and descenders:
243+
# Find full vertical extent of font,
244+
# including ascenders and descenders:
255245
tmp, heightt = renderer.get_text_width_height(
256-
'Tglp', self._fontproperties, ismath=False)
246+
'lp', self._fontproperties, ismath=False)
247+
offsety = heightt * self._linespacing
257248

258249
for line in lines:
259250
w,h = renderer.get_text_width_height(
260251
line, self._fontproperties, ismath=self.is_math_text())
261-
262252
whs.append( (w,h) )
263-
offsety = heightt * self._linespacing
264253
horizLayout.append((line, thisx, thisy, w, h))
265-
thisy -= offsety # now translate down by text height, window coords
254+
thisy -= offsety
266255
width = max(width, w)
267256

268257
ymin = horizLayout[-1][2]
@@ -627,6 +616,7 @@ def set_multialignment(self, align):
627616
def set_linespacing(self, spacing):
628617
"""
629618
Set the line spacing as a multiple of the font size.
619+
Default is 1.2.
630620
631621
ACCEPTS: float
632622
"""
@@ -888,6 +878,7 @@ def __init__(self,
888878
multialignment=None,
889879
fontproperties=None, # defaults to FontProperties()
890880
rotation=None,
881+
linespacing=None,
891882
dashlength=0.0,
892883
dashdirection=0,
893884
dashrotation=None,
@@ -900,7 +891,9 @@ def __init__(self,
900891
verticalalignment=verticalalignment,
901892
horizontalalignment=horizontalalignment,
902893
multialignment=multialignment,
903-
fontproperties=fontproperties, rotation=rotation)
894+
fontproperties=fontproperties,
895+
rotation=rotation,
896+
linespacing=linespacing)
904897

905898
# The position (x,y) values for text and dashline
906899
# are bogus as given in the instantiation; they will

0 commit comments

Comments
 (0)