There was an error while loading. Please reload this page.
2 parents 7af53bb + d156691 commit 48031d8Copy full SHA for 48031d8
2 files changed
lib/matplotlib/contour.py
@@ -250,7 +250,7 @@ def get_label_width(self, lev, fmt, fsize):
250
fig = self.axes.figure
251
width = (text.Text(0, 0, lev, figure=fig,
252
size=fsize, fontproperties=self.labelFontProps)
253
- .get_window_extent(fig.canvas.get_renderer()).width)
+ .get_window_extent(mpl.tight_layout.get_renderer(fig)).width)
254
width *= 72 / fig.dpi
255
return width
256
lib/matplotlib/tests/test_contour.py
@@ -392,3 +392,9 @@ def test_contour_linewidth(
392
X = np.arange(4*3).reshape(4, 3)
393
cs = ax.contour(X, linewidths=call_linewidths)
394
assert cs.tlinewidths[0][0] == expected
395
+
396
397
+@pytest.mark.backend("pdf")
398
+def test_label_nonagg():
399
+ # This should not crash even if the canvas doesn't have a get_renderer().
400
+ plt.clabel(plt.contour([[1, 2], [3, 4]]))
0 commit comments