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

I changed the offset code for draw_text for RendererAgg fixing issue #13044#20057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
safdarzareef wants to merge1 commit intomatplotlib:mainfromsafdarzareef:text-rotation-patch
Closed
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletionslib/matplotlib/backends/backend_agg.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@
except ImportError:
import dummy_threading as threading
from contextlib import nullcontext
from math import radians, cos, sin
from math import radians, cos, sin, sqrt

import numpy as np
from PIL import Image
Expand DownExpand Up@@ -208,10 +208,13 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
xo, yo = font.get_bitmap_offset()
xo /= 64.0
yo /= 64.0
h = sqrt(xo**2 + yo**2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Personally, I prefer usinghypot() instead, but I don't know if it really matters in the context of bounding box calculations.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't know if it will matter, but we could still change it.

xd = d * sin(radians(angle))
yd = d * cos(radians(angle))
xo = h * cos(radians(angle))
yo = h * sin(radians(angle))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If we are going to calculateradians(angle) four times, might as well just do it once and store it in a variable.

safdarzareef reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Also, these four lines here would greatly benefit from a comment explaining the trigonometry. Usually, cos() goes with x, and y goes with sin(). Seeing it two different ways here for the offset and the descent is confusing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I can explain the offset trigonometry, but I just left the code for the descent as it was before. The descent seems wrong - but I am unaware of the reason why it was like that before so I left it there. Basic trigonometry suggests that x components should be calculated by multiplying a number by the cosine of its angle and y components should be calculated by multiplying a number by the sine of its angle - so that is why I used that for the offset but I do think the descent should be in the same form too.

x = round(x + xo + xd)
y = round(y + yo+ yd)
y = round(y + yo- yd)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

much like the trig above, I think this will also need a quick proof in the comments.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't think I have a proof for this at the moment except that in the draw_mathtext function the y is calculated in a similar manner and by subtracting the y offset we get a satisfactory result.

self._renderer.draw_text_image(font, x, y + 1, angle, gc)

def get_text_width_height_descent(self, s, prop, ismath):
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp