Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6009467

Browse files
author
Wiliam
committed
Implement the changes to the text rotation
1 parent758a399 commit6009467

File tree

49 files changed

+14
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+14
-4
lines changed

‎lib/matplotlib/backends/backend_agg.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,20 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
197197
xo,yo=font.get_bitmap_offset()
198198
xo/=64.0
199199
yo/=64.0
200-
xd=d*sin(radians(angle))
201-
yd=d*cos(radians(angle))
202-
x=round(x+xo+xd)
203-
y=round(y+yo+yd)
200+
201+
rad=radians(angle)
202+
xd=d*sin(rad)
203+
yd=d*cos(rad)
204+
# Rotating the offset vector ensures text rotates around the anchor point.
205+
# Without this, rotated text offsets incorrectly, causing a horizontal shift.
206+
# Applying the 2D rotation matrix.
207+
rotated_xo=xo*cos(rad)-yo*sin(rad)
208+
rotated_yo=xo*sin(rad)+yo*cos(rad)
209+
# Subtract rotated_yo to account for the inverted y-axis in computer graphics,
210+
# compared to the mathematical convention.
211+
x=round(x+rotated_xo+xd)
212+
y=round(y-rotated_yo+yd)
213+
204214
self._renderer.draw_text_image(font,x,y+1,angle,gc)
205215

206216
defget_text_width_height_descent(self,s,prop,ismath):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp