@@ -186,19 +186,23 @@ def draw_box(ax, tt):
186
186
ax .text (1.2 , 0.1 , 'Bot align, rot20' , color = 'C2' )
187
187
188
188
189
- @image_comparison (['antialiased.png' ])
189
+ @image_comparison (['antialiased.png' ], style = 'mpl20' )
190
190
def test_antialiasing ():
191
- mpl .rcParams ['text.antialiased' ] = True
191
+ mpl .rcParams ['text.antialiased' ] = False # Passed arguments should override.
192
192
193
193
fig = plt .figure (figsize = (5.25 , 0.75 ))
194
- fig .text (0.5 , 0.75 , "antialiased" , horizontalalignment = 'center' ,
195
- verticalalignment = 'center' )
196
- fig .text (0.5 , 0.25 , r"$\sqrt{x}$" , horizontalalignment = 'center' ,
197
- verticalalignment = 'center' )
198
- # NOTE: We don't need to restore the rcParams here, because the
199
- # test cleanup will do it for us. In fact, if we do it here, it
200
- # will turn antialiasing back off before the images are actually
201
- # rendered.
194
+ fig .text (0.3 , 0.75 , "antialiased" , horizontalalignment = 'center' ,
195
+ verticalalignment = 'center' , antialiased = True )
196
+ fig .text (0.3 , 0.25 , r"$\sqrt{x}$" , horizontalalignment = 'center' ,
197
+ verticalalignment = 'center' , antialiased = True )
198
+
199
+ mpl .rcParams ['text.antialiased' ] = True # Passed arguments should override.
200
+ fig .text (0.7 , 0.75 , "not antialiased" , horizontalalignment = 'center' ,
201
+ verticalalignment = 'center' , antialiased = False )
202
+ fig .text (0.7 , 0.25 , r"$\sqrt{x}$" , horizontalalignment = 'center' ,
203
+ verticalalignment = 'center' , antialiased = False )
204
+
205
+ mpl .rcParams ['text.antialiased' ] = False # Should not affect existing text.
202
206
203
207
204
208
def test_afm_kerning ():
@@ -914,29 +918,18 @@ def test_annotate_offset_fontsize():
914
918
assert str (points_coords ) == str (fontsize_coords )
915
919
916
920
917
- def test_set_antialiased ():
921
+ def test_get_set_antialiased ():
918
922
txt = Text (.5 , .5 , "foo\n bar" )
919
923
assert txt ._antialiased == mpl .rcParams ['text.antialiased' ]
924
+ assert txt .get_antialiased () == mpl .rcParams ['text.antialiased' ]
920
925
921
926
txt .set_antialiased (True )
922
927
assert txt ._antialiased is True
928
+ assert txt .get_antialiased () == txt ._antialiased
923
929
924
930
txt .set_antialiased (False )
925
931
assert txt ._antialiased is False
926
-
927
-
928
- def test_get_antialiased ():
929
-
930
- txt2 = Text (.5 , .5 , "foo\n bar" , antialiased = True )
931
- assert txt2 ._antialiased is True
932
- assert txt2 .get_antialiased () == txt2 ._antialiased
933
-
934
- txt3 = Text (.5 , .5 , "foo\n bar" , antialiased = False )
935
- assert txt3 ._antialiased is False
936
- assert txt3 .get_antialiased () == txt3 ._antialiased
937
-
938
- txt4 = Text (.5 , .5 , "foo\n bar" )
939
- assert txt4 .get_antialiased () == mpl .rcParams ['text.antialiased' ]
932
+ assert txt .get_antialiased () == txt ._antialiased
940
933
941
934
942
935
def test_annotation_antialiased ():
@@ -957,39 +950,6 @@ def test_annotation_antialiased():
957
950
assert annot4 ._antialiased == mpl .rcParams ['text.antialiased' ]
958
951
959
952
960
- @check_figures_equal ()
961
- def test_text_antialiased_off_default_vs_manual (fig_test , fig_ref ):
962
- fig_test .text (0.5 , 0.5 , '6 inches x 2 inches' ,
963
- antialiased = False )
964
-
965
- mpl .rcParams ['text.antialiased' ] = False
966
- fig_ref .text (0.5 , 0.5 , '6 inches x 2 inches' )
967
-
968
-
969
- @check_figures_equal ()
970
- def test_text_antialiased_on_default_vs_manual (fig_test , fig_ref ):
971
- fig_test .text (0.5 , 0.5 , '6 inches x 2 inches' , antialiased = True )
972
-
973
- mpl .rcParams ['text.antialiased' ] = True
974
- fig_ref .text (0.5 , 0.5 , '6 inches x 2 inches' )
975
-
976
-
977
- @check_figures_equal ()
978
- def test_text_math_antialiased_on_default_vs_manual (fig_test , fig_ref ):
979
- fig_test .text (0.5 , 0.5 , r"OutsideMath $I\'m \sqrt{2}$" , antialiased = True )
980
-
981
- mpl .rcParams ['text.antialiased' ] = True
982
- fig_ref .text (0.5 , 0.5 , r"OutsideMath $I\'m \sqrt{2}$" )
983
-
984
-
985
- @check_figures_equal ()
986
- def test_text_math_antialiased_off_default_vs_manual (fig_test , fig_ref ):
987
- fig_test .text (0.5 , 0.5 , r"OutsideMath $I\'m \sqrt{2}$" , antialiased = False )
988
-
989
- mpl .rcParams ['text.antialiased' ] = False
990
- fig_ref .text (0.5 , 0.5 , r"OutsideMath $I\'m \sqrt{2}$" )
991
-
992
-
993
953
@check_figures_equal (extensions = ["png" ])
994
954
def test_annotate_and_offsetfrom_copy_input (fig_test , fig_ref ):
995
955
# Both approaches place the text (10, 0) pixels away from the center of the line.
0 commit comments