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

Skip to content

Fix clabel() for backends without canvas.get_renderer() #18968

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 1 commit into from
Nov 18, 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
2 changes: 1 addition & 1 deletion lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def get_label_width(self, lev, fmt, fsize):
fig = self.axes.figure
width = (text.Text(0, 0, lev, figure=fig,
size=fsize, fontproperties=self.labelFontProps)
.get_window_extent(fig.canvas.get_renderer()).width)
.get_window_extent(mpl.tight_layout.get_renderer(fig)).width)
width *= 72 / fig.dpi
return width

Expand Down
6 changes: 6 additions & 0 deletions lib/matplotlib/tests/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,9 @@ def test_contour_linewidth(
X = np.arange(4*3).reshape(4, 3)
cs = ax.contour(X, linewidths=call_linewidths)
assert cs.tlinewidths[0][0] == expected


@pytest.mark.backend("pdf")
def test_label_nonagg():
# This should not crash even if the canvas doesn't have a get_renderer().
plt.clabel(plt.contour([[1, 2], [3, 4]]))