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

Skip to content

Remove font warning when legend is added while using Tex #17521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/matplotlib/offsetbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,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, d = 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