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

Skip to content

Commit 89a248d

Browse files
committed
fixed some text rotation bugs
svn path=/trunk/matplotlib/; revision=813
1 parent 565d614 commit 89a248d

8 files changed

Lines changed: 58 additions & 9 deletions

File tree

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
New entries should be added at the top
22

3+
2004-12-23 Fixed an agg text rotation alignment bug, fixed some text
4+
kwarg processing bugs, and added examples/text_rotation.py
5+
to explain and demonstrate how text rotations and alignment
6+
work in matplotlib. - JDH
7+
38
======================================================================
49

510
2004-12-22 0.65.1 released - JDH

TODO

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,4 +614,6 @@ ZeroDivisionError: SeparableTransformation::eval_scalars yin interval is zero; c
614614

615615
-- fix linestyle for collections
616616

617-
-- update ticklabels and range for colorbar when clim changes
617+
-- update ticklabels and range for colorbar when clim changes
618+
619+
-- agg rotation bug for angles > 180

examples/backend_driver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
# 'set_and_get.py',
6161
'table_demo.py',
6262
'text_handles.py',
63+
'text_rotation.py',
6364
'text_themes.py',
6465
'two_scales.py',
6566
'vline_demo.py',

examples/text_rotation.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
The way matplotlib does text layout is counter-intuituve to some, so
3+
this example is designed to make it a little clearer. The text is
4+
aligned by it's bounding box (the rectangular box that surrounds the
5+
ink rectangle). The order of opertations is basically rotation then
6+
alignment, rather than alignment then rotation. Basically, the text
7+
is centered at your x,y location, rotated around this point, and then
8+
aligned according to the bounding box of the rotated text.
9+
10+
So if you specify left, bottom alignment, the bottom left of the
11+
bounding box of the rotated text will be at the x,y coordinate of the
12+
text.
13+
14+
But a picture is worth a thousand words!
15+
"""
16+
from pylab import *
17+
18+
def addtext(props):
19+
text(0.5, 0.5, 'text 0', props, rotation=0)
20+
text(1.5, 0.5, 'text 45', props, rotation=45)
21+
text(2.5, 0.5, 'text 135', props, rotation=135)
22+
text(3.5, 0.5, 'text 225', props, rotation=225)
23+
text(4.5, 0.5, 'text -45', props, rotation=-45)
24+
yticks([0,.5,1])
25+
grid(True)
26+
27+
# the text bounding box
28+
bbox = {'fc':0.8, 'pad':0}
29+
30+
subplot(211)
31+
addtext({'ha':'center', 'va':'center', 'bbox':bbox})
32+
xlim(0,5)
33+
xticks(arange(0, 5.1, 0.5), [])
34+
ylabel('center / center')
35+
subplot(212)
36+
addtext({'ha':'left', 'va':'bottom', 'bbox':bbox})
37+
xlim(0,5)
38+
xticks(arange(0, 5.1, 0.5))
39+
ylabel('left / bottom')
40+
show()

lib/matplotlib/axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,7 @@ def set_ylabel(self, ylabel, fontdict=None, **kwargs):
26002600
label = self.yaxis.get_label()
26012601
label.set_text(ylabel)
26022602

2603-
if fontdict is not None: self.title.update(label)
2603+
if fontdict is not None: self.title.update(fontdict)
26042604
label.update(kwargs)
26052605
return label
26062606

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ def show(self):
286286
if not self._shown:
287287
self.window.deiconify()
288288
# anim.py requires this
289-
if sys.platform=='win32' : self.window.update()
289+
if not sys.platform.startswith('linux') :
290+
self.window.update()
290291
else: self.canvas.draw()
291292
self._shown = True
292293
def destroy(*args):

lib/matplotlib/text.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,15 @@ def get_window_extent(self, renderer):
320320

321321
def get_rotation_matrix(self, x0, y0):
322322

323-
theta = -pi/180.0*self.get_rotation()
323+
theta = pi/180.0*self.get_rotation()
324324
# translate x0,y0 to origin
325325
Torigin = Matrix([ [1, 0, -x0],
326326
[0, 1, -y0],
327327
[0, 0, 1 ]])
328328

329329
# rotate by theta
330-
R = Matrix([ [cos(theta), sin(theta), 0],
331-
[-sin(theta), cos(theta), 0],
330+
R = Matrix([ [cos(theta), -sin(theta), 0],
331+
[sin(theta), cos(theta), 0],
332332
[0, 0, 1]])
333333

334334
# translate origin back to x0,y0

src/ft2font.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ FT2Font::set_text(const Py::Tuple & args) {
416416
_VERBOSE("FT2Font::set_text");
417417
args.verify_length(2);
418418
text = Py::String(args[0]);
419-
double angle = Py::Float(args[1]);
419+
angle = Py::Float(args[1]);
420420

421421
angle = angle/360.0*2*3.14159;
422422
//this computes width and height in subpixels so we have to divide by 64
@@ -669,9 +669,9 @@ FT2Font::draw_glyphs_to_bitmap(const Py::Tuple & args) {
669669
image.offsetx = (int)(string_bbox.xMin/64.0);
670670
if (angle==0)
671671
image.offsety = -image.height;
672-
else
672+
else {
673673
image.offsety = (int)(-string_bbox.yMax/64.0);
674-
674+
}
675675

676676
size_t numBytes = image.width*image.height;
677677
delete [] image.buffer;

0 commit comments

Comments
 (0)