Skip to content

BUG: Fix NonUniformImage with nonlinear scale #27964

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 2 commits into from
Apr 17, 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
10 changes: 7 additions & 3 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,12 +1085,16 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
B[:, :, 0:3] = A
B[:, :, 3] = 255
A = B
vl = self.axes.viewLim
l, b, r, t = self.axes.bbox.extents
width = int(((round(r) + 0.5) - (round(l) - 0.5)) * magnification)
height = int(((round(t) + 0.5) - (round(b) - 0.5)) * magnification)
x_pix = np.linspace(vl.x0, vl.x1, width)
y_pix = np.linspace(vl.y0, vl.y1, height)

invertedTransform = self.axes.transData.inverted()
x_pix = invertedTransform.transform(
[(x, b) for x in np.linspace(l, r, width)])[:, 0]
y_pix = invertedTransform.transform(
[(l, y) for y in np.linspace(b, t, height)])[:, 1]

if self._interpolation == "nearest":
x_mid = (self._Ax[:-1] + self._Ax[1:]) / 2
y_mid = (self._Ay[:-1] + self._Ay[1:]) / 2
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,27 @@ def test_nonuniform_and_pcolor():
ax.set(xlim=(0, 10))


@image_comparison(["nonuniform_logscale.png"], style="mpl20")
def test_nonuniform_logscale():
_, axs = plt.subplots(ncols=3, nrows=1)

for i in range(3):
ax = axs[i]
im = NonUniformImage(ax)
im.set_data(np.arange(1, 4) ** 2, np.arange(1, 4) ** 2,
np.arange(9).reshape((3, 3)))
ax.set_xlim(1, 16)
ax.set_ylim(1, 16)
ax.set_box_aspect(1)
if i == 1:
ax.set_xscale("log", base=2)
ax.set_yscale("log", base=2)
if i == 2:
ax.set_xscale("log", base=4)
ax.set_yscale("log", base=4)
ax.add_image(im)


@image_comparison(
['rgba_antialias.png'], style='mpl20', remove_text=True,
tol=0 if platform.machine() == 'x86_64' else 0.007)
Expand Down
Loading