Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix imshow edges #8300

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

Closed
wants to merge 3 commits into from
Closed
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
14 changes: 5 additions & 9 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,6 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
mask = A.mask
# ~A.mask # masked data
A = rgba
output = np.zeros((out_height, out_width, 4),
dtype=A.dtype)
alpha = 1.0
created_rgba_mask = True
else:
Expand All @@ -414,15 +412,13 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
elif A.shape[2] != 4:
raise ValueError("Invalid dimensions, got %s" % (A.shape,))

output = np.zeros((out_height, out_width, 4), dtype=A.dtype)

alpha = self.get_alpha()
if alpha is None:
alpha = 1.0

output = np.zeros((out_height, out_width, 4), dtype=A.dtype)

_image.resample(
A, output, t, _interpd_[self.get_interpolation()],
self.get_resample(), alpha,
self.get_resample(), alpha if alpha is not None else 1,
self.get_filternorm() or 0.0, self.get_filterrad() or 0.0)

if created_rgba_mask:
Expand All @@ -447,7 +443,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
# and the pixels that Agg is telling us to ignore (relavent
# to non-affine transforms)
# Use half alpha as the threshold for pixels to mask.
out_mask = out_mask | (hid_output[..., 3] < .5)
out_mask = out_mask | (hid_output[..., 3] == 0)
output = np.ma.masked_array(
hid_output[..., 0],
out_mask)
Expand All @@ -465,9 +461,9 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,

# Apply alpha *after* if the input was greyscale without a mask
if A.ndim == 2 or created_rgba_mask:
alpha_channel = output[:, :, 3]
alpha = self.get_alpha()
if alpha is not None and alpha != 1.0:
alpha_channel = output[:, :, 3]
alpha_channel[:] = np.asarray(
np.asarray(alpha_channel, np.float32) * alpha,
np.uint8)
Expand Down
Binary file modified lib/matplotlib/tests/baseline_images/test_image/rotate_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from numpy.testing import (
assert_array_equal, assert_array_almost_equal, assert_allclose)
from matplotlib.testing.noseclasses import KnownFailureTest
from copy import copy
from copy import deepcopy
from numpy import ma
import matplotlib.image as mimage
import matplotlib.colors as colors
Expand Down Expand Up @@ -155,6 +155,7 @@ def test_imsave():

assert_array_equal(arr_dpi1, arr_dpi100)

@cleanup
def test_imsave_color_alpha():
# Test that imsave accept arrays with ndim=3 where the third dimension is
# color and alpha without raising any exceptions, and that the data is
Expand Down Expand Up @@ -698,7 +699,7 @@ def test_mask_image_over_under():
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = 10*(Z2 - Z1) # difference of Gaussians

palette = copy(plt.cm.gray)
palette = deepcopy(plt.cm.gray)
palette.set_over('r', 1.0)
palette.set_under('g', 1.0)
palette.set_bad('b', 1.0)
Expand Down Expand Up @@ -761,7 +762,7 @@ def test_imshow_endianess():
remove_text=True, style='default')
def test_imshow_masked_interpolation():

cm = copy(plt.get_cmap('viridis'))
cm = deepcopy(plt.get_cmap('viridis'))
cm.set_over('r')
cm.set_under('b')
cm.set_bad('k')
Expand Down