Skip to content

Commit e475af9

Browse files
committed
Test that text is located correctly with xcolor.
1 parent 87bc31f commit e475af9

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

lib/matplotlib/testing/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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"))

lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
from io import BytesIO
33
import os
44
import shutil
5-
import subprocess
65

76
import numpy as np
87
import pytest
98

109
import matplotlib as mpl
1110
import matplotlib.pyplot as plt
12-
from matplotlib.testing import check_for_pgf
11+
from matplotlib.testing import _has_tex_package, check_for_pgf
1312
from matplotlib.testing.compare import compare_images, ImageComparisonFailure
1413
from matplotlib.backends.backend_pgf import PdfPages, common_texification
1514
from matplotlib.testing.decorators import (_image_directories,
@@ -29,10 +28,6 @@
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-
3631
def compare_figure(fname, savefig_kwargs={}, tol=0):
3732
actual = os.path.join(result_dir, fname)
3833
plt.savefig(actual, **savefig_kwargs)

lib/matplotlib/tests/test_usetex.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pytest
33

44
import matplotlib as mpl
5+
from matplotlib.testing import _has_tex_package
56
from matplotlib.testing.decorators import check_figures_equal, image_comparison
67
import 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+
83101
def test_textcomp_full():
84102
plt.rcParams["text.latex.preamble"] = r"\usepackage[full]{textcomp}"
85103
fig = plt.figure()

0 commit comments

Comments
 (0)