8000 Merge pull request #25989 from saranti/offset_fontsize · matplotlib/matplotlib@3218d1f · GitHub
[go: up one dir, main page]

Skip to content

Commit 3218d1f

Browse files
authored
Merge pull request #25989 from saranti/offset_fontsize
test annotate(textcoords=offset fontsize)
2 parents 86e544a + ecbc1c9 commit 3218d1f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/matplotlib/tests/test_text.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,3 +886,19 @@ def call(*args, **kwargs):
886886
# Every string gets a miss for the first layouting (extents), then a hit
887887
# when drawing, but "foo\nbar" gets two hits as it's drawn twice.
888888
assert info.hits > info.misses
889+
890+
891+
def test_annotate_offset_fontsize():
892+
# Test that offset_fontsize parameter works and uses accurate values
893+
fig, ax = plt.subplots()
894+
text_coords = ['offset points', 'offset fontsize']
895+
# 10 points should be equal to 1 fontsize unit at fontsize=10
896+
xy_text = [(10, 10), (1, 1)]
897+
anns = [ax.annotate('test', xy=(0.5, 0.5),
898+
xytext=xy_text[i],
899+
fontsize='10',
900+
xycoords='data',
901+
textcoords=text_coords[i]) for i in range(2)]
902+
points_coords, fontsize_coords = [ann.get_window_extent() for ann in anns]
903+
fig.canvas.draw()
904+
assert str(points_coords) == str(fontsize_coords)

0 commit comments

Comments
 (0)
0