|
16 | 16 | import matplotlib.transforms as mtransforms |
17 | 17 | from matplotlib.testing.decorators import check_figures_equal, image_comparison |
18 | 18 | from matplotlib.testing._markers import needs_usetex |
19 | | -from matplotlib.text import Text, Annotation |
| 19 | +from matplotlib.text import Text, Annotation, OffsetFrom |
20 | 20 |
|
21 | 21 | pyparsing_version = parse_version(pyparsing.__version__) |
22 | 22 |
|
@@ -988,3 +988,19 @@ def test_text_math_antialiased_off_default_vs_manual(fig_test, fig_ref): |
988 | 988 |
|
989 | 989 | mpl.rcParams['text.antialiased'] = False |
990 | 990 | fig_ref.text(0.5, 0.5, r"OutsideMath $I\'m \sqrt{2}$") |
| 991 | + |
| 992 | + |
| 993 | +@check_figures_equal(extensions=["png"]) |
| 994 | +def test_annotate_and_offsetfrom_copy_input(fig_test, fig_ref): |
| 995 | + # Both approaches place the text (10, 0) pixels away from the center of the line. |
| 996 | + ax = fig_test.add_subplot() |
| 997 | + l, = ax.plot([0, 2], [0, 2]) |
| 998 | + of_xy = np.array([.5, .5]) |
| 999 | + ax.annotate("foo", textcoords=OffsetFrom(l, of_xy), xytext=(10, 0), |
| 1000 | + xy=(0, 0)) # xy is unused. |
| 1001 | + of_xy[:] = 1 |
| 1002 | + ax = fig_ref.add_subplot() |
| 1003 | + l, = ax.plot([0, 2], [0, 2]) |
| 1004 | + an_xy = np.array([.5, .5]) |
| 1005 | + ax.annotate("foo", xy=an_xy, xycoords=l, xytext=(10, 0), textcoords="offset points") |
| 1006 | + an_xy[:] = 2 |
0 commit comments