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

Skip to content

Commit 9c6342d

Browse files
committed
Make the filternorm prop of Images a boolean rather than a {0,1} scalar.
This seems a bit more pythonic and the C-API handles bools just as well. Also filternorm and filterrad are always defined (as bool and float, respectively, so no need to add `... or 0.0` when passing them to the C-API.
1 parent 2099af4 commit 9c6342d

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5410,13 +5410,13 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
54105410
shape : scalars (columns, rows), optional, default: None
54115411
For raw buffer images
54125412
5413-
filternorm : scalar, optional, default: 1
5414-
A parameter for the antigrain image resize filter. From the
5415-
antigrain documentation, if `filternorm` = 1, the filter
5413+
filternorm : bool, optional, default: True
5414+
A parameter for the antigrain image resize filter (see the
5415+
antigrain documentation). If *filternorm* is set, the filter
54165416
normalizes integer values and corrects the rounding errors. It
54175417
doesn't do anything with the source floating point values, it
54185418
corrects only integers according to the rule of 1.0 which means
5419-
that any sum of pixel weights must be equal to 1.0. So, the
5419+
that any sum of pixel weights must be equal to 1.0. So, the
54205420
filter function must produce a graph of the proper shape.
54215421
54225422
filterrad : scalar, optional, default: 4.0

lib/matplotlib/image.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def __init__(self, ax,
206206
norm=None,
207207
interpolation=None,
208208
origin=None,
209-
filternorm=1,
209+
filternorm=True,
210210
filterrad=4.0,
211211
resample=False,
212212
**kwargs
@@ -412,8 +412,8 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
412412
t,
413413
_interpd_[self.get_interpolation()],
414414
self.get_resample(), 1.0,
415-
self.get_filternorm() or 0.0,
416-
self.get_filterrad() or 0.0)
415+
self.get_filternorm(),
416+
self.get_filterrad())
417417

418418
# we are done with A_scaled now, remove from namespace
419419
# to be sure!
@@ -447,8 +447,8 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
447447
t,
448448
_interpd_[self.get_interpolation()],
449449
True, 1,
450-
self.get_filternorm() or 0.0,
451-
self.get_filterrad() or 0.0)
450+
self.get_filternorm(),
451+
self.get_filterrad())
452452
# we are done with the mask, delete from namespace to be sure!
453453
del mask
454454
# Agg updates the out_mask in place. If the pixel has
@@ -481,7 +481,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
481481
_image.resample(
482482
A, output, t, _interpd_[self.get_interpolation()],
483483
self.get_resample(), alpha,
484-
self.get_filternorm() or 0.0, self.get_filterrad() or 0.0)
484+
self.get_filternorm(), self.get_filterrad())
485485

486486
# at this point output is either a 2D array of normed data
487487
# (of int or float)
@@ -720,20 +720,17 @@ def get_resample(self):
720720

721721
def set_filternorm(self, filternorm):
722722
"""
723-
Set whether the resize filter norms the weights -- see
724-
help for imshow
723+
Set whether the resize filter normalizes the weights.
725724
726-
ACCEPTS: 0 or 1
727-
"""
728-
if filternorm:
729-
self._filternorm = 1
730-
else:
731-
self._filternorm = 0
725+
See help for `~.Axes.imshow`.
732726
727+
.. ACCEPTS: bool
728+
"""
729+
self._filternorm = bool(filternorm)
733730
self.stale = True
734731

735732
def get_filternorm(self):
736-
"""Return the filternorm setting."""
733+
"""Return whether the resize filter normalizes the weights."""
737734
return self._filternorm
738735

739736
def set_filterrad(self, filterrad):

0 commit comments

Comments
 (0)