File tree Expand file tree Collapse file tree 3 files changed +27
-6
lines changed Expand file tree Collapse file tree 3 files changed +27
-6
lines changed Original file line number Diff line number Diff line change 4
4
5
5
import locale
6
6
import logging
7
+ import shutil
8
+ import subprocess
7
9
8
10
import matplotlib as mpl
9
11
from matplotlib import _api
@@ -44,3 +46,9 @@ def setup():
44
46
# are not necessarily the default values as specified in rcsetup.py.
45
47
set_font_settings_for_testing ()
46
48
set_reproducibility_for_testing ()
49
+
50
+
51
+ def _has_tex_package (package ):
52
+ return (shutil .which ("kpsewhich" )
53
+ and subprocess .run (["kpsewhich" , f"{ package } .sty" ],
54
+ stdout = subprocess .PIPE ).returncode == 0 )
Original file line number Diff line number Diff line change 11
11
12
12
import matplotlib as mpl
13
13
import matplotlib .pyplot as plt
14
+ from matplotlib .testing import _has_tex_package
14
15
from matplotlib .testing .compare import compare_images , ImageComparisonFailure
15
16
from matplotlib .backends .backend_pgf import PdfPages , common_texification
16
17
from matplotlib .testing .decorators import (_image_directories ,
@@ -51,12 +52,6 @@ def check_for(texsystem):
51
52
reason = "This test needs a ghostscript installation" )
52
53
53
54
54
- def _has_tex_package (package ):
55
- return (shutil .which ("kpsewhich" )
56
- and subprocess .run (["kpsewhich" , f"{ package } .sty" ],
57
- stdout = subprocess .PIPE ).returncode == 0 )
58
-
59
-
60
55
def compare_figure (fname , savefig_kwargs = {}, tol = 0 ):
61
56
actual = os .path .join (result_dir , fname )
62
57
plt .savefig (actual , ** savefig_kwargs )
Original file line number Diff line number Diff line change 2
2
import pytest
3
3
4
4
import matplotlib as mpl
5
+ from matplotlib .testing import _has_tex_package
5
6
from matplotlib .testing .decorators import check_figures_equal , image_comparison
6
7
import matplotlib .pyplot as plt
7
8
@@ -80,6 +81,23 @@ def test_minus_no_descent(fontsize):
80
81
assert len ({* heights .values ()}) == 1
81
82
82
83
84
+ @pytest .mark .skipif (_has_tex_package ('xcolor.sty' ),
85
+ reason = 'xcolor is not available' )
86
+ def test_usetex_xcolor ():
87
+ mpl .rcParams ['text.usetex' ] = True
88
+
89
+ fig = plt .figure ()
90
+ t = fig .text (0.5 , 0.5 , "Some text 0123456789" )
91
+ fig .canvas .draw ()
92
+ pos = t .get_window_extent ()
93
+
94
+ mpl .rcParams ['text.latex.preamble' ] = r'\usepackage[dvipsnames]{xcolor}'
95
+ fig = plt .figure ()
96
+ t = fig .text (0.5 , 0.5 , "Some text 0123456789" )
97
+ fig .canvas .draw ()
98
+ np .testing .assert_array_equal (t .get_window_extent (), pos )
99
+
100
+
83
101
def test_textcomp_full ():
84
102
plt .rcParams ["text.latex.preamble" ] = r"\usepackage[full]{textcomp}"
85
103
fig = plt .figure ()
You can’t perform that action at this time.
0 commit comments