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

Fix Agg extent calculations for empty draws #12117

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 15, 2018
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 8 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 13 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.