|
14 | 14 | import matplotlib.transforms as mtransforms |
15 | 15 | from matplotlib.testing.decorators import check_figures_equal, image_comparison |
16 | 16 | from matplotlib.testing._markers import needs_usetex |
17 | | -from matplotlib.text import Text |
| 17 | +from matplotlib.text import Text, Annotation |
18 | 18 |
|
19 | 19 |
|
20 | 20 | @image_comparison(['font_styles']) |
@@ -886,3 +886,74 @@ def call(*args, **kwargs): |
886 | 886 | # Every string gets a miss for the first layouting (extents), then a hit |
887 | 887 | # when drawing, but "foo\nbar" gets two hits as it's drawn twice. |
888 | 888 | assert info.hits > info.misses |
| 889 | + |
| 890 | + |
| 891 | +def test_set_antialiased(): |
| 892 | + txt = Text(.5, .5, "foo\nbar") |
| 893 | + assert txt._antialiased == mpl.rcParams['text.antialiased'] |
| 894 | + |
| 895 | + txt.set_antialiased(True) |
| 896 | + assert txt._antialiased is True |
| 897 | + |
| 898 | + txt.set_antialiased(False) |
| 899 | + assert txt._antialiased is False |
| 900 | + |
| 901 | + |
| 902 | +def test_get_antialiased(): |
| 903 | + |
| 904 | + txt2 = Text(.5, .5, "foo\nbar", antialiased=True) |
| 905 | + assert txt2._antialiased is True |
| 906 | + assert txt2.get_antialiased() == txt2._antialiased |
| 907 | + |
| 908 | + txt3 = Text(.5, .5, "foo\nbar", antialiased=False) |
| 909 | + assert txt3._antialiased is False |
| 910 | + assert txt3.get_antialiased() == txt3._antialiased |
| 911 | + |
| 912 | + txt4 = Text(.5, .5, "foo\nbar") |
| 913 | + assert txt4.get_antialiased() == mpl.rcParams['text.antialiased'] |
| 914 | + |
| 915 | + |
| 916 | +def test_annotation_antialiased(): |
| 917 | + annot = Annotation("foo\nbar", (.5, .5), antialiased=True) |
| 918 | + assert annot._antialiased is True |
| 919 | + assert annot.get_antialiased() == annot._antialiased |
| 920 | + |
| 921 | + annot2 = Annotation("foo\nbar", (.5, .5), antialiased=False) |
| 922 | + assert annot2._antialiased is False |
| 923 | + assert annot2.get_antialiased() == annot2._antialiased |
| 924 | + |
| 925 | + annot3 = Annotation("foo\nbar", (.5, .5), antialiased=False) |
| 926 | + annot3.set_antialiased(True) |
| 927 | + assert annot3.get_antialiased() is True |
| 928 | + assert annot3._antialiased is True |
| 929 | + |
| 930 | + annot4 = Annotation("foo\nbar", (.5, .5)) |
| 931 | + assert annot4._antialiased == mpl.rcParams['text.antialiased'] |
| 932 | + |
| 933 | + |
| 934 | +@check_figures_equal() |
| 935 | +def test_text_antialiased_off_default_vs_manual(fig_test, fig_ref): |
| 936 | + # note that the field antialiased is for Text object |
| 937 | + # therefore in the test we will make axis antialiasing identical |
| 938 | + # which is determined by rcParams['text.antialiased'] when axis is created |
| 939 | + # also note that there is no way to change this for axis after creating it |
| 940 | + |
| 941 | + mpl.rcParams['text.antialiased'] = False |
| 942 | + # axis: antialiased == rcParams['text.antialiased'] == False |
| 943 | + # text: antialiased == False |
| 944 | + fig_test.subplots().text(0.5, 0.5, '6 inches x 2 inches', |
| 945 | + antialiased=False) |
| 946 | + |
| 947 | + mpl.rcParams['text.antialiased'] = False |
| 948 | + # axis: antialiased == rcParams['text.antialiased'] == False |
| 949 | + # text: antialiased == rcParams['text.antialiased'] == False |
| 950 | + fig_ref.subplots().text(0.5, 0.5, '6 inches x 2 inches') |
| 951 | + |
| 952 | + |
| 953 | +@check_figures_equal() |
| 954 | +def test_text_antialiased_on_default_vs_manual(fig_test, fig_ref): |
| 955 | + mpl.rcParams['text.antialiased'] = True |
| 956 | + fig_test.subplots().text(0.5, 0.5, '6 inches x 2 inches', antialiased=True) |
| 957 | + |
| 958 | + mpl.rcParams['text.antialiased'] = True |
| 959 | + fig_ref.subplots().text(0.5, 0.5, '6 inches x 2 inches') |
0 commit comments