Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6406646

Browse files
authored
Merge pull request #17521 from Struan-Murray/e17518
Remove font warning when legend is added while using Tex
2 parents 3b576e6 + bb0786b commit 6406646

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/matplotlib/offsetbox.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,8 @@ def get_window_extent(self, renderer):
882882

883883
def get_extent(self, renderer):
884884
_, h_, d_ = renderer.get_text_width_height_descent(
885-
"lp", self._text._fontproperties, ismath=False)
885+
"lp", self._text._fontproperties,
886+
ismath="TeX" if self._text.get_usetex() else False)
886887

887888
bbox, info, yd = self._text._get_layout(renderer)
888889
w, h = bbox.width, bbox.height

lib/matplotlib/tests/test_legend.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,22 @@ def test_alpha_handles():
637637
assert lh.get_edgecolor()[:-1] == hh[1].get_edgecolor()[:-1]
638638

639639

640+
@pytest.mark.skipif(
641+
not mpl.checkdep_usetex(True),
642+
reason="This test needs a TeX installation")
643+
def test_usetex_no_warn(caplog):
644+
mpl.rcParams['font.family'] = 'serif'
645+
mpl.rcParams['font.serif'] = 'Computer Modern'
646+
mpl.rcParams['text.usetex'] = True
647+
648+
fig, ax = plt.subplots()
649+
ax.plot(0, 0, label='input')
650+
ax.legend(title="My legend")
651+
652+
fig.canvas.draw()
653+
assert "Font family ['serif'] not found." not in caplog.text
654+
655+
640656
def test_warn_big_data_best_loc():
641657
fig, ax = plt.subplots()
642658
fig.canvas.draw() # So that we can call draw_artist later.

0 commit comments

Comments
 (0)