File tree Expand file tree Collapse file tree 3 files changed +23
-6
lines changed
Expand file tree Collapse file tree 3 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -75,3 +75,7 @@ def check_for_pgf(texsystem):
7575 except (OSError , subprocess .CalledProcessError ):
7676 return False
7777 return True
78+
79+
80+ def _has_tex_package (package ):
81+ return bool (mpl .dviread .find_tex_file (f"{ package } .sty" ))
Original file line number Diff line number Diff line change 22from io import BytesIO
33import os
44import shutil
5- import subprocess
65
76import numpy as np
87import pytest
98
109import matplotlib as mpl
1110import matplotlib .pyplot as plt
12- from matplotlib .testing import check_for_pgf
11+ from matplotlib .testing import _has_tex_package , check_for_pgf
1312from matplotlib .testing .compare import compare_images , ImageComparisonFailure
1413from matplotlib .backends .backend_pgf import PdfPages , common_texification
1514from matplotlib .testing .decorators import (_image_directories ,
2928 reason = "This test needs a ghostscript installation" )
3029
3130
32- def _has_tex_package (package ):
33- return bool (mpl .dviread .find_tex_file (f"{ package } .sty" ))
34-
35-
3631def compare_figure (fname , savefig_kwargs = {}, tol = 0 ):
3732 actual = os .path .join (result_dir , fname )
3833 plt .savefig (actual , ** savefig_kwargs )
Original file line number Diff line number Diff line change 22import pytest
33
44import matplotlib as mpl
5+ from matplotlib .testing import _has_tex_package
56from matplotlib .testing .decorators import check_figures_equal , image_comparison
67import matplotlib .pyplot as plt
78
@@ -80,6 +81,23 @@ def test_minus_no_descent(fontsize):
8081 assert len ({* heights .values ()}) == 1
8182
8283
84+ @pytest .mark .skipif (not _has_tex_package ('xcolor' ),
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+
83101def test_textcomp_full ():
84102 plt .rcParams ["text.latex.preamble" ] = r"\usepackage[full]{textcomp}"
85103 fig = plt .figure ()
You can’t perform that action at this time.
0 commit comments