Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4f1f1a8

Browse filesBrowse files
authored
Merge pull request #12125 from meeseeksmachine/auto-backport-of-pr-12117-on-v2.2.x
Backport PR #12117 on branch v2.2.x (Fix Agg extent calculations for empty draws)
2 parents 06e3dd0 + bfa8b88 commit 4f1f1a8
Copy full SHA for 4f1f1a8

File tree

Expand file treeCollapse file tree

2 files changed

+17
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-4
lines changed

‎lib/matplotlib/tests/test_backend_pdf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_pdf.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,11 @@ def test_failing_latex(tmpdir):
238238
plt.xlabel("$22_2_2$")
239239
with pytest.raises(RuntimeError):
240240
plt.savefig(path)
241+
242+
243+
def test_empty_rasterised():
244+
# Check that emtpy figures that are rasterised save to pdf files fine
245+
with PdfPages(io.BytesIO()) as pdf:
246+
fig, ax = plt.subplots()
247+
ax.plot([], [], rasterized=True)
248+
fig.savefig(pdf, format="pdf")

‎src/_backend_agg.cpp

Copy file name to clipboardExpand all lines: src/_backend_agg.cpp
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,15 @@ agg::rect_i RendererAgg::get_content_extents()
213213
}
214214
}
215215

216-
r.x1 = std::max(0, r.x1);
217-
r.y1 = std::max(0, r.y1);
218-
r.x2 = std::min(r.x2 + 1, (int)width);
219-
r.y2 = std::min(r.y2 + 1, (int)height);
216+
if (r.x1 == width && r.x2 == 0) {
217+
// The buffer is completely empty.
218+
r.x1 = r.y1 = r.x2 = r.y2 = 0;
219+
} else {
220+
r.x1 = std::max(0, r.x1);
221+
r.y1 = std::max(0, r.y1);
222+
r.x2 = std::min(r.x2 + 1, (int)width);
223+
r.y2 = std::min(r.y2 + 1, (int)height);
224+
}
220225

221226
return r;
222227
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.