Skip to content

Commit ac8cfb3

Browse files
committed
Merge pull request matplotlib#5817 from tacaswell/backport
Merge pull request matplotlib#5815 from mdboom/fix-minimizing-raster-layer
2 parents c1a2dc5 + 0631a1d commit ac8cfb3

File tree

2 files changed

+55
-9
lines changed

2 files changed

+55
-9
lines changed

lib/matplotlib/tests/test_image.py

+51-5
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,32 @@
22
unicode_literals)
33

44
from matplotlib.externals import six
5+
import sys
6+
import io
7+
import os
58

69
import numpy as np
710

8-
from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup
11+
from matplotlib.testing.decorators import (image_comparison,
12+
knownfailureif, cleanup)
913
from matplotlib.image import BboxImage, imread, NonUniformImage
1014
from matplotlib.transforms import Bbox
1115
from matplotlib import rcParams
1216
import matplotlib.pyplot as plt
13-
from nose.tools import assert_raises
14-
from numpy.testing import assert_array_equal, assert_array_almost_equal
1517

16-
import io
17-
import os
18+
from numpy.testing import assert_array_equal
19+
20+
21+
import nose
1822

1923
try:
2024
from PIL import Image
25+
del Image
2126
HAS_PIL = True
2227
except ImportError:
2328
HAS_PIL = False
2429

30+
2531
@image_comparison(baseline_images=['image_interps'])
2632
def test_image_interps():
2733
'make the basic nearest, bilinear and bicubic interps'
@@ -447,12 +453,52 @@ def test_nonuniformimage_setcmap():
447453
im = NonUniformImage(ax)
448454
im.set_cmap('Blues')
449455

456+
450457
@cleanup
451458
def test_nonuniformimage_setnorm():
452459
ax = plt.gca()
453460
im = NonUniformImage(ax)
454461
im.set_norm(plt.Normalize())
455462

463+
464+
@cleanup
465+
def test_minimized_rasterized():
466+
# This ensures that the rasterized content in the colorbars is
467+
# only as thick as the colorbar, and doesn't extend to other parts
468+
# of the image. See #5814. While the original bug exists only
469+
# in Postscript, the best way to detect it is to generate SVG
470+
# and then parse the output to make sure the two colorbar images
471+
# are the same size.
472+
if sys.version_info[:2] < (2, 7):
473+
raise nose.SkipTest("xml.etree.ElementTree.Element.iter "
474+
"added in py 2.7")
475+
476+
from xml.etree import ElementTree
477+
478+
np.random.seed(0)
479+
data = np.random.rand(10, 10)
480+
481+
fig, ax = plt.subplots(1, 2)
482+
p1 = ax[0].pcolormesh(data)
483+
p2 = ax[1].pcolormesh(data)
484+
485+
plt.colorbar(p1, ax=ax[0])
486+
plt.colorbar(p2, ax=ax[1])
487+
488+
buff = io.BytesIO()
489+
plt.savefig(buff, format='svg')
490+
491+
buff = io.BytesIO(buff.getvalue())
492+
tree = ElementTree.parse(buff)
493+
width = None
494+
for image in tree.iter('image'):
495+
if width is None:
496+
width = image['width']
497+
else:
498+
if image['width'] != width:
499+
assert False
500+
501+
456502
if __name__=='__main__':
457503
import nose
458504
nose.runmodule(argv=['-s','--with-doctest'], exit=False)

src/_backend_agg.cpp

+4-4
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)