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

Skip to content

Commit 0b56e07

Browse files
committed
Add an rcparam for image.interpolation_stage.
1 parent 42472ef commit 0b56e07

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``image.interpolation_stage`` rcParam
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
This new rcParam controls whether image interpolation occurs in "data" space or
4+
in "rgba" space.

lib/matplotlib/image.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,10 +789,9 @@ def set_interpolation_stage(self, s):
789789
----------
790790
s : {'data', 'rgba'} or None
791791
Whether to apply up/downsampling interpolation in data or RGBA
792-
space.
792+
space. If None, use :rc:`image.interpolation_stage`.
793793
"""
794-
if s is None:
795-
s = "data" # placeholder for maybe having rcParam
794+
s = mpl._val_or_rc(s, 'image.interpolation_stage')
796795
_api.check_in_list(['data', 'rgba'], s=s)
797796
self._interpolation_stage = s
798797
self.stale = True

lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@
603603
## ***************************************************************************
604604
#image.aspect: equal # {equal, auto} or a number
605605
#image.interpolation: antialiased # see help(imshow) for options
606+
#image.interpolation_stage: data # see help(imshow) for options
606607
#image.cmap: viridis # A colormap name (plasma, magma, etc.)
607608
#image.lut: 256 # the size of the colormap lookup table
608609
#image.origin: upper # {lower, upper}

lib/matplotlib/rcsetup.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,12 +1051,13 @@ def _convert_validator_spec(key, conv):
10511051
"bb", "frak", "scr", "regular"],
10521052
"mathtext.fallback": _validate_mathtext_fallback,
10531053

1054-
"image.aspect": validate_aspect, # equal, auto, a number
1055-
"image.interpolation": validate_string,
1056-
"image.cmap": _validate_cmap, # gray, jet, etc.
1057-
"image.lut": validate_int, # lookup table
1058-
"image.origin": ["upper", "lower"],
1059-
"image.resample": validate_bool,
1054+
"image.aspect": validate_aspect, # equal, auto, a number
1055+
"image.interpolation": validate_string,
1056+
"image.interpolation_stage": ["data", "rgba"],
1057+
"image.cmap": _validate_cmap, # gray, jet, etc.
1058+
"image.lut": validate_int, # lookup table
1059+
"image.origin": ["upper", "lower"],
1060+
"image.resample": validate_bool,
10601061
# Specify whether vector graphics backends will combine all images on a
10611062
# set of Axes into a single composite image
10621063
"image.composite_image": validate_bool,

lib/matplotlib/tests/test_image.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,15 @@ def test_rgba_antialias():
14621462
cmap=cmap, vmin=-1.2, vmax=1.2)
14631463

14641464

1465+
def test_rc_interpolation_stage():
1466+
for val in ["data", "rgba"]:
1467+
with mpl.rc_context({"image.interpolation_stage": val}):
1468+
assert plt.imshow([[1, 2]]).get_interpolation_stage() == val
1469+
for val in ["DATA", "foo", None]:
1470+
with pytest.raises(ValueError):
1471+
mpl.rcParams["image.interpolation_stage"] = val
1472+
1473+
14651474
# We check for the warning with a draw() in the test, but we also need to
14661475
# filter the warning as it is emitted by the figure test decorator
14671476
@pytest.mark.filterwarnings(r'ignore:Data with more than .* '

0 commit comments

Comments
 (0)