File tree 2 files changed +17
-4
lines changed
2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -238,3 +238,11 @@ def test_failing_latex(tmpdir):
238
238
plt .xlabel ("$22_2_2$" )
239
239
with pytest .raises (RuntimeError ):
240
240
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" )
Original file line number Diff line number Diff line change @@ -213,10 +213,15 @@ agg::rect_i RendererAgg::get_content_extents()
213
213
}
214
214
}
215
215
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
+ }
220
225
221
226
return r;
222
227
}
You can’t perform that action at this time.
0 commit comments