8000 Merge pull request #5815 from mdboom/fix-minimizing-raster-layer · matplotlib/matplotlib@1acc296 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 1acc296

Browse files
committed
Merge pull request #5815 from mdboom/fix-minimizing-raster-layer
Properly minimize the rasterized layers Conflicts: lib/matplotlib/tests/test_image.py One too-many tests were cherry-picked
1 parent 5ea0a5b commit 1acc296

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

lib/matplotlib/tests/test_image.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,48 @@ def test_nonuniformimage_setcmap():
447447
im = NonUniformImage(ax)
448448
im.set_cmap('Blues')
449449

450+
450451
@cleanup
451452
def test_nonuniformimage_setnorm():
452453
ax = plt.gca()
453454
im = NonUniformImage(ax)
454455
im.set_norm(plt.Normalize())
455456

457+
458+
@cleanup
459+
def test_minimized_rasterized():
460+
# This ensures that the rasterized content in the colorbars is
461+
# only as thick as the colorbar, and doesn't extend to other parts
462+
# of the image. See #5814. While the original bug exists only
463+
# in Postscript, the best way to detect it is to generate SVG
464+
# and then parse the output to make sure the two colorbar images
465+
# are the same size.
466+
from xml.etree import ElementTree
467+
468+
np.random.seed(0)
469+
data = np.random.rand(10, 10)
470+
471+
fig, ax = plt.subplots(1, 2)
472+
p1 = ax[0].pcolormesh(data)
473+
p2 = ax[1].pcolormesh(data)
474+
475+
plt.colorbar(p1, ax=ax[0])
476+
plt.colorbar(p2, ax=ax[1])
477+
478+
buff = io.BytesIO()
479+
plt.savefig(buff, format='svg 8000 9;)
480+
481+
buff = io.BytesIO(buff.getvalue())
482+
tree = ElementTree.parse(buff)
483+
width = None
484+
for image in tree.iter('image'):
485+
if width is None:
486+
width = image['width']
487+
else:
488+
if image['width'] != width:
489+
assert False
490+
491+
456492
if __name__=='__main__':
457493
import nose
458494
nose.runmodule(argv=['-s','--with-doctest'], exit=False)

src/_backend_agg.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ agg::rect_i RendererAgg::get_content_extents()
210210
}
211211
}
212212

213-
r.x1 = std::max(0, r.x1 - 1);
214-
r.y1 = std::max(0, r.y1 - 1);
215-
r.x2 = std::max(r.x2 + 1, (int)width);
216-
r.y2 = std::max(r.y2 + 1, (int)height);
213+
r.x1 = std::max(0, r.x1);
214+
r.y1 = std::max(0, r.y1);
215+
r.x2 = std::min(r.x2 + 1, (int)width);
216+
r.y2 = std::min(r.y2 + 1, (int)height);
217217

218218
return r;
219219
}

0 commit comments

Comments
 (0)
0