Skip to content

Add an rcparam for image.interpolation_stage. #27730

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 1 commit into from
Mar 21, 2024
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
4 changes: 4 additions & 0 deletions doc/users/next_whats_new/interpolation_stage_rc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
``image.interpolation_stage`` rcParam
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This new rcParam controls whether image interpolation occurs in "data" space or
in "rgba" space.
5 changes: 2 additions & 3 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,10 +789,9 @@ def set_interpolation_stage(self, s):
----------
s : {'data', 'rgba'} or None
Whether to apply up/downsampling interpolation in data or RGBA
space.
space. If None, use :rc:`image.interpolation_stage`.
"""
if s is None:
s = "data" # placeholder for maybe having rcParam
s = mpl._val_or_rc(s, 'image.interpolation_stage')
_api.check_in_list(['data', 'rgba'], s=s)
self._interpolation_stage = s
self.stale = True
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/mpl-data/matplotlibrc
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@
## ***************************************************************************
#image.aspect: equal # {equal, auto} or a number
#image.interpolation: antialiased # see help(imshow) for options
#image.interpolation_stage: data # see help(imshow) for options
#image.cmap: viridis # A colormap name (plasma, magma, etc.)
#image.lut: 256 # the size of the colormap lookup table
#image.origin: upper # {lower, upper}
Expand Down
13 changes: 7 additions & 6 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,12 +1051,13 @@ def _convert_validator_spec(key, conv):
"bb", "frak", "scr", "regular"],
"mathtext.fallback": _validate_mathtext_fallback,

"image.aspect": validate_aspect, # equal, auto, a number
"image.interpolation": validate_string,
"image.cmap": _validate_cmap, # gray, jet, etc.
"image.lut": validate_int, # lookup table
"image.origin": ["upper", "lower"],
"image.resample": validate_bool,
"image.aspect": validate_aspect, # equal, auto, a number
"image.interpolation": validate_string,
"image.interpolation_stage": ["data", "rgba"],
"image.cmap": _validate_cmap, # gray, jet, etc.
"image.lut": validate_int, # lookup table
"image.origin": ["upper", "lower"],
"image.resample": validate_bool,
# Specify whether vector graphics backends will combine all images on a
# set of Axes into a single composite image
"image.composite_image": validate_bool,
Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,15 @@ def test_rgba_antialias():
cmap=cmap, vmin=-1.2, vmax=1.2)


def test_rc_interpolation_stage():
for val in ["data", "rgba"]:
with mpl.rc_context({"image.interpolation_stage": val}):
assert plt.imshow([[1, 2]]).get_interpolation_stage() == val
for val in ["DATA", "foo", None]:
with pytest.raises(ValueError):
mpl.rcParams["image.interpolation_stage"] = val


# We check for the warning with a draw() in the test, but we also need to
# filter the warning as it is emitted by the figure test decorator
@pytest.mark.filterwarnings(r'ignore:Data with more than .* '
Expand Down