Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 98506d0

Browse filesBrowse files
authored
Merge pull request matplotlib#27964 from AnsonTran/fix-logscale-axis
BUG: Fix NonUniformImage with nonlinear scale
2 parents a218d5c + 919a6cb commit 98506d0
Copy full SHA for 98506d0

File tree

Expand file treeCollapse file tree

4 files changed

+28
-3
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+28
-3
lines changed

‎lib/matplotlib/image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/image.py
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,12 +1085,16 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
10851085
B[:, :, 0:3] = A
10861086
B[:, :, 3] = 255
10871087
A = B
1088-
vl = self.axes.viewLim
10891088
l, b, r, t = self.axes.bbox.extents
10901089
width = int(((round(r) + 0.5) - (round(l) - 0.5)) * magnification)
10911090
height = int(((round(t) + 0.5) - (round(b) - 0.5)) * magnification)
1092-
x_pix = np.linspace(vl.x0, vl.x1, width)
1093-
y_pix = np.linspace(vl.y0, vl.y1, height)
1091+
1092+
invertedTransform = self.axes.transData.inverted()
1093+
x_pix = invertedTransform.transform(
1094+
[(x, b) for x in np.linspace(l, r, width)])[:, 0]
1095+
y_pix = invertedTransform.transform(
1096+
[(l, y) for y in np.linspace(b, t, height)])[:, 1]
1097+
10941098
if self._interpolation == "nearest":
10951099
x_mid = (self._Ax[:-1] + self._Ax[1:]) / 2
10961100
y_mid = (self._Ay[:-1] + self._Ay[1:]) / 2
Loading
Loading

‎lib/matplotlib/tests/test_image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_image.py
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,27 @@ def test_nonuniform_and_pcolor():
14141414
ax.set(xlim=(0, 10))
14151415

14161416

1417+
@image_comparison(["nonuniform_logscale.png"], style="mpl20")
1418+
def test_nonuniform_logscale():
1419+
_, axs = plt.subplots(ncols=3, nrows=1)
1420+
1421+
for i in range(3):
1422+
ax = axs[i]
1423+
im = NonUniformImage(ax)
1424+
im.set_data(np.arange(1, 4) ** 2, np.arange(1, 4) ** 2,
1425+
np.arange(9).reshape((3, 3)))
1426+
ax.set_xlim(1, 16)
1427+
ax.set_ylim(1, 16)
1428+
ax.set_box_aspect(1)
1429+
if i == 1:
1430+
ax.set_xscale("log", base=2)
1431+
ax.set_yscale("log", base=2)
1432+
if i == 2:
1433+
ax.set_xscale("log", base=4)
1434+
ax.set_yscale("log", base=4)
1435+
ax.add_image(im)
1436+
1437+
14171438
@image_comparison(
14181439
['rgba_antialias.png'], style='mpl20', remove_text=True,
14191440
tol=0 if platform.machine() == 'x86_64' else 0.007)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.