Skip to content
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
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,11 @@ def test_failing_latex(tmpdir):
plt.xlabel("$22_2_2$")
with pytest.raises(RuntimeError):
plt.savefig(path)


def test_empty_rasterised():
# Check that emtpy figures that are rasterised save to pdf files fine
with PdfPages(io.BytesIO()) as pdf:
fig, ax = plt.subplots()
ax.plot([], [], rasterized=True)
fig.savefig(pdf, format="pdf")
13 changes: 9 additions & 4 deletions src/_backend_agg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,15 @@ agg::rect_i RendererAgg::get_content_extents()
}
}

r.x1 = std::max(0, r.x1);
r.y1 = std::max(0, r.y1);
r.x2 = std::min(r.x2 + 1, (int)width);
r.y2 = std::min(r.y2 + 1, (int)height);
if (r.x1 == width && r.x2 == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes a warning now:

src/_backend_agg.cpp: In member function ‘agg::rect_i RendererAgg::get_content_extents()’:
src/_backend_agg.cpp:204:14: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]
     if (r.x1 == width && r.x2 == 0) {
         ~~~~~^~~~~~~~

// The buffer is completely empty.
r.x1 = r.y1 = r.x2 = r.y2 = 0;
} else {
r.x1 = std::max(0, r.x1);
r.y1 = std::max(0, r.y1);
r.x2 = std::min(r.x2 + 1, (int)width);
r.y2 = std::min(r.y2 + 1, (int)height);
}

return r;
}
Expand Down