Skip to content

Unexpected behaviour of imshow default interpolation #19838

Closed

Description

@Trel725

Bug report

Bug summary

Artifacts appear when plotting periodic data with discontinuities, i.e. something like x mod 1.0
The bug appears at when render resolution is relatively small comparing to the real resolution of the data (downsampling problem?).

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

xx, yy = np.meshgrid(np.linspace(-5, 5, 201), np.linspace(-5, 5, 201))
psi = xx % 1.0

plt.figure()
plt.imshow(psi, cmap="twilight")
plt.savefig("small.png", dpi=100)
plt.savefig("large.png", dpi=200)

Outcome

alt text alt text

(large.png, small.png)

Matplotlib version

The issue is repeatable locally and in CoLab:

  • Operating system: Linux
  • Matplotlib version: 3.3.3, 3.2.2
  • Matplotlib backend (): TkAgg, ipykernel.pylab.backend_inline
  • Python version: 3.8.5, 3.7

Activity

  1. jklymak commented on Mar 31, 2021

    @jklymak
    Member

    Yes, this is a consequence of the interpolation being done in data space rather than colourspace, so your jumps at 0,1 get interpolated as ~0.5, and show up as a purple line.

    There is a bit of a religious war about this among the devs, where some devs think that any interpolation that creates pixels that are not in the colormap is anathema. While of course that is true for interpolation, or smoothing of an image, others of us do not think that is true for downsampling. See #18782 and issues linked therein for more discussion.

  2. linked a pull request that will close this issueENH: allow image to interpolate post RGBA #18782on Mar 31, 2021
  3. added this to the v3.5.0 milestone on Mar 31, 2021
  4. QuLogic commented on Mar 31, 2021

    @QuLogic
    Member

    Closing as a duplicate of one of the issues linked to the above PR. I'm not sure which one, but there's no need to have a bunch of these open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions