Skip to content

Merge pull request #5815 from mdboom/fix-minimizing-raster-layer #5817

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 3 commits into from
Jan 10, 2016
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
56 changes: 51 additions & 5 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,32 @@
unicode_literals)

from matplotlib.externals import six
import sys
import io
import os

import numpy as np

from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup
from matplotlib.testing.decorators import (image_comparison,
knownfailureif, cleanup)
from matplotlib.image import BboxImage, imread, NonUniformImage
from matplotlib.transforms import Bbox
from matplotlib import rcParams
import matplotlib.pyplot as plt
from nose.tools import assert_raises
from numpy.testing import assert_array_equal, assert_array_almost_equal

import io
import os
from numpy.testing import assert_array_equal


import nose

try:
from PIL import Image
del Image
HAS_PIL = True
except ImportError:
HAS_PIL = False


@image_comparison(baseline_images=['image_interps'])
def test_image_interps():
'make the basic nearest, bilinear and bicubic interps'
Expand Down Expand Up @@ -447,12 +453,52 @@ def test_nonuniformimage_setcmap():
im = NonUniformImage(ax)
im.set_cmap('Blues')


@cleanup
def test_nonuniformimage_setnorm():
ax = plt.gca()
im = NonUniformImage(ax)
im.set_norm(plt.Normalize())


@cleanup
def test_minimized_rasterized():
# This ensures that the rasterized content in the colorbars is
# only as thick as the colorbar, and doesn't extend to other parts
# of the image. See #5814. While the original bug exists only
# in Postscript, the best way to detect it is to generate SVG
# and then parse the output to make sure the two colorbar images
# are the same size.
if sys.version_info[:2] < (2, 7):
raise nose.SkipTest("xml.etree.ElementTree.Element.iter "
"added in py 2.7")

from xml.etree import ElementTree

np.random.seed(0)
data = np.random.rand(10, 10)

fig, ax = plt.subplots(1, 2)
p1 = ax[0].pcolormesh(data)
p2 = ax[1].pcolormesh(data)

plt.colorbar(p1, ax=ax[0])
plt.colorbar(p2, ax=ax[1])

buff = io.BytesIO()
plt.savefig(buff, format='svg')

buff = io.BytesIO(buff.getvalue())
tree = ElementTree.parse(buff)
width = None
for image in tree.iter('image'):
if width is None:
width = image['width']
else:
if image['width'] != width:
assert False


if __name__=='__main__':
import nose
nose.runmodule(argv=['-s','--with-doctest'], exit=False)
8 changes: 4 additions & 4 deletions src/_backend_agg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ agg::rect_i RendererAgg::get_content_extents()
}
}

r.x1 = std::max(0, r.x1 - 1);
r.y1 = std::max(0, r.y1 - 1);
r.x2 = std::max(r.x2 + 1, (int)width);
r.y2 = std::max(r.y2 + 1, (int)height);
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