Skip to content

Navigation Menu

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

Appearance settings

Commit 6009467

Browse filesBrowse files
author
Wiliam
committed
Implement the changes to the text rotation
1 parent 758a399 commit 6009467
Copy full SHA for 6009467

Some content is hidden

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

49 files changed

+14
-4
lines changed

‎lib/matplotlib/backends/backend_agg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_agg.py
+14-4Lines 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
def get_text_width_height_descent(self, s, prop, ismath):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.