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

Skip to content

Commit 4dc049a

Browse files
committed
update annotations
1 parent f677f36 commit 4dc049a

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

lib/matplotlib/tests/test_text.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import matplotlib
99
import matplotlib.pyplot as plt
1010
from matplotlib.testing.decorators import image_comparison
11+
from matplotlib.gridspec import GridSpec
1112

1213

1314
needs_usetex = pytest.mark.skipif(
@@ -499,3 +500,19 @@ def test_text_repr():
499500
plt.plot(['A', 'B'], [1, 2])
500501
txt = plt.text(['A'], 0.5, 'Boo')
501502
print(txt)
503+
504+
505+
@image_comparison(baseline_images=['text_annotation'],
506+
extensions=['png'])
507+
def test_annotation():
508+
fig = plt.figure()
509+
spec = matplotlib.gridspec.GridSpec(ncols=3, nrows=3)
510+
anno_opts = dict(xy=(0.5, 0.5), xycoords='axes fraction',
511+
va='center', ha='center')
512+
513+
fig.add_subplot(spec[0, 0]).annotate('GridSpec[0, 0]', **anno_opts)
514+
fig.add_subplot(spec[0, 1:]).annotate('GridSpec[0, 1:]', **anno_opts)
515+
fig.add_subplot(spec[1:, 0]).annotate('GridSpec[1:, 0]', **anno_opts)
516+
fig.add_subplot(spec[1:, 1:]).annotate('GridSpec[1:, 1:]', **anno_opts)
517+
518+
fig.tight_layout()

lib/matplotlib/text.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,7 @@ def get_window_extent(self, renderer=None):
23542354
*dpi* used defaults to self.figure.dpi; the renderer dpi is
23552355
irrelevant.
23562356
'''
2357+
self.update_positions(renderer)
23572358
if not self.get_visible():
23582359
return Bbox.unit()
23592360

0 commit comments

Comments
 (0)