8000 FIX · matplotlib/matplotlib@4bf6bf1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4bf6bf1

Browse files
committed
FIX
1 parent f44136e commit 4bf6bf1

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -432,15 +432,13 @@ def draw_image(self, gc, x, y, im, transform=None, true_size=None):
432432
# docstring inherited
433433

434434
h, w = im.shape[:2]
435+
print('PRE', h, w)
436+
435437
if h == 0 or w == 0:
436438
return
437439
if true_size is not None:
438-
w, h = true_size
439-
print('HEY', h, w)
440-
w = int(w * self.image_magnification)
441-
h = int(h * self.image_magnification)
442-
print('HEY', h, w, self.image_magnification)
443-
440+
w0, h0 = true_size
441+
print('HEY', w, h, w0, h0, self.image_magnification)
444442

445443
imagecmd = "false 3 colorimage"
446444
data = im[::-1, :, :3] # Vertically flipped rgb values.
@@ -452,8 +450,9 @@ def draw_image(self, gc, x, y, im, transform=None, true_size=None):
452450
xscale = w / self.image_magnification
453451
yscale = h / self.image_magnification
454452
else:
455-
xscale = w / self.image_magnification
456-
yscale = h / self.image_magnification
453+
xscale = w0
454+
yscale = h0
455+
print('scale', xscale, yscale)
457456
else:
458457
xscale = 1.0
459458
yscale = 1.0
@@ -462,9 +461,9 @@ def draw_image(self, gc, x, y, im, transform=None, true_size=None):
462461
self._pswriter.write(f"""\
463462
gsave
464463
{self._get_clip_cmd(gc)}
465-
{x:g} {y:g} translate
464+
{x:.2f} {y:.2f} translate
466465
[{matrix}] concat
467-
{xscale:g} {yscale:g} scale
466+
{xscale:.2f} {yscale:.2f} scale
468467
/DataString {w:d} string def
469468
{w:d} {h:d} 8 [ {w:d} 0 0 -{h:d} 0 {h:d} ]
470469
{{

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,12 @@ def test_colorbar_shift(tmp_path):
336336
norm = mcolors.BoundaryNorm([-1, -0.5, 0.5, 1], cmap.N)
337337
plt.scatter([0, 1], [1, 1], c=[0, 1], cmap=cmap, norm=norm)
338338
plt.colorbar()
339+
340+
341+
@image_comparison(["colorbar_raster.eps"], savefig_kwarg={"dpi": 20},
342+
style="mpl20")
343+
def test_colorbar_rasterized(tmp_path):
344+
fig, ax = plt.subplots()
345+
np.random.seed(19680801)
346+
pc = ax.pcolormesh(np.random.randn(30, 30), rasterized=True)
347+
fig.colorbar(pc)

0 commit comments

Comments
 (0)
0