Skip to content

Commit

Permalink
Merge pull request #17521 from Struan-Murray/e17518
Browse files Browse the repository at this point in the history
Remove font warning when legend is added while using Tex
  • Loading branch information
dstansby committed Sep 20, 2020
2 parents 3b576e6 + bb0786b commit 6406646
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/matplotlib/offsetbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,8 @@ def get_window_extent(self, renderer):

def get_extent(self, renderer):
_, h_, d_ = renderer.get_text_width_height_descent(
"lp", self._text._fontproperties, ismath=False)
"lp", self._text._fontproperties,
ismath="TeX" if self._text.get_usetex() else False)

bbox, info, yd = self._text._get_layout(renderer)
w, h = bbox.width, bbox.height
Expand Down
16 changes: 16 additions & 0 deletions lib/matplotlib/tests/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,22 @@ def test_alpha_handles():
assert lh.get_edgecolor()[:-1] == hh[1].get_edgecolor()[:-1]


@pytest.mark.skipif(
not mpl.checkdep_usetex(True),
reason="This test needs a TeX installation")
def test_usetex_no_warn(caplog):
mpl.rcParams['font.family'] = 'serif'
mpl.rcParams['font.serif'] = 'Computer Modern'
mpl.rcParams['text.usetex'] = True

fig, ax = plt.subplots()
ax.plot(0, 0, label='input')
ax.legend(title="My legend")

fig.canvas.draw()
assert "Font family ['serif'] not found." not in caplog.text


def test_warn_big_data_best_loc():
fig, ax = plt.subplots()
fig.canvas.draw() # So that we can call draw_artist later.
Expand Down

0 comments on commit 6406646

Please sign in to comment.