Skip to content

test annotate(textcoords=offset fontsize) #25989

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2023
Merged
Changes from all 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
16 changes: 16 additions & 0 deletions lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,3 +886,19 @@ def call(*args, **kwargs):
# Every string gets a miss for the first layouting (extents), then a hit
# when drawing, but "foo\nbar" gets two hits as it's drawn twice.
assert info.hits > info.misses


def test_annotate_offset_fontsize():
# Test that offset_fontsize parameter works and uses accurate values
fig, ax = plt.subplots()
text_coords = ['offset points', 'offset fontsize']
# 10 points should be equal to 1 fontsize unit at fontsize=10
xy_text = [(10, 10), (1, 1)]
anns = [ax.annotate('test', xy=(0.5, 0.5),
xytext=xy_text[i],
fontsize='10',
xycoords='data',
textcoords=text_coords[i]) for i in range(2)]
points_coords, fontsize_coords = [ann.get_window_extent() for ann in anns]
fig.canvas.draw()
assert str(points_coords) == str(fontsize_coords)