Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6e3edc

Browse files
committed
added test for Annotation.set_position
1 parent 38b9385 commit f6e3edc

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lib/matplotlib/tests/test_text.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,34 @@ def test_alignment():
194194
ax.set_ylim([0, 1.5])
195195
ax.set_xticks([])
196196
ax.set_yticks([])
197+
198+
199+
@cleanup
200+
def test_set_position():
201+
fig, ax = plt.subplots()
202+
203+
# test set_position
204+
ann = ax.annotate('test', (0, 0), xytext=(0, 0), textcoords='figure pixels')
205+
plt.draw()
206+
207+
init_pos = ann.get_window_extent(fig.canvas.renderer)
208+
shift_val = 15
209+
ann.set_position((shift_val, shift_val))
210+
plt.draw()
211+
post_pos = ann.get_window_extent(fig.canvas.renderer)
212+
213+
for a, b in zip(init_pos.min, post_pos.min):
214+
assert a + shift_val == b
215+
216+
# test xyann
217+
ann = ax.annotate('test', (0, 0), xytext=(0, 0), textcoords='figure pixels')
218+
plt.draw()
219+
220+
init_pos = ann.get_window_extent(fig.canvas.renderer)
221+
shift_val = 15
222+
ann.xyann = (shift_val, shift_val)
223+
plt.draw()
224+
post_pos = ann.get_window_extent(fig.canvas.renderer)
225+
226+
for a, b in zip(init_pos.min, post_pos.min):
227+
assert a + shift_val == b

0 commit comments

Comments
 (0)