Skip to content

[Bug]: Logscale Axis + NonUniformImage + GUI move tool = Distortion #27820

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
DonaldHobson opened this issue Feb 24, 2024 · 2 comments · Fixed by #27964
Closed

[Bug]: Logscale Axis + NonUniformImage + GUI move tool = Distortion #27820

DonaldHobson opened this issue Feb 24, 2024 · 2 comments · Fixed by #27964

Comments

@DonaldHobson
Copy link

Bug summary

Run the code below, which uses set.xscale("log") and NonUniformImage. Choose the move tool (Arrows in all 4 directions) and try to pan the image around. Instead of panning, image distorts.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.image import NonUniformImage

chg=np.logspace(0,1,10)
chg1=chg[:,None]
chg2=chg[None,:]
g=chg1+chg2
g+=50*(np.add.outer(np.arange(10),np.arange(10))%2)
#checkerboard, to make effect clearer
fig,ax=plt.subplots()
ax.set_xscale("log")
ax.set_yscale("log")
im=NonUniformImage(ax,extent=[chg[0],chg[-1],chg[0],chg[-1]],origin="lower")


im.set_data(np.linspace(1,10,10),np.linspace(1,10,10),g)
ax.add_image(im)

plt.show()

Actual outcome

image
image

These are supposed to be the same image. I just used the pan tool.
But the aspect ratio has changed. And the boundary of the rightmost colour change has gone from 0.75 to 0.5.

Clicking and dragging produces behaviour that is visually obviously not-right.

Expected outcome

The image should pan around.

Additional information

No bug appears when I use a plt.imshow on the log scale axis. Or when I use the same NonUniformImage code without the logscale axis. The bug only appears with all 3 conditions are met.

I was trying to find a sensible way to display an image on log-log axes with constant screen space per pixel, when I discovered this bug.

Operating system

Ubuntu

Matplotlib Version

3.8.0

Matplotlib Backend

QtAgg

Python version

Python 3.11.5

Jupyter version

No response

Installation

conda

@jklymak
Copy link
Member

jklymak commented Feb 25, 2024

Suggest using pcolormesh for this.

@dstansby
Copy link
Member

dstansby commented Feb 25, 2024

The boundaries not being correct does actually behave the same way on a linear scale - if you scroll past the lower limit (1) in the example above the axes stays blue, instead of scrolling past the image into an empty white area.

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

Successfully merging a pull request may close this issue.

4 participants