Skip to content

gap between x-axis and image when rasterized=True, vector backend, and manually placed axes #18051

Closed
@aerusso

Description

@aerusso

Bug report

Bug summary

imshow (and friends, e.g., pcolormesh) don't tightly fit the image inside the axes. I suspect an off-by-one error somewhere (see the hint section at the bottom).

Code for reproduction

from matplotlib import pyplot as plt

fig = plt.figure(figsize=(3.423,2.92917))
ax = plt.Axes(fig, [0.2,0.2,0.2,0.2])
fig.add_axes(ax)

ax.imshow([[1,2],[3,4]],rasterized=True)
plt.savefig('gap.pdf')

Actual outcome

gap.pdf

Expected outcome

There should be no gap between the x axis, and the image.

Matplotlib version

  • Operating system: linux
  • Matplotlib version: 3.2.2 (but also later 3.4.0)
  • Python version: 3.8

Hints

I don't have time to dig into this right now, but it is corrected (for my particular figure size) by subtracting 1 from the y parameter in the draw_image call in the stop_rasterizing definition of backend_mixed.py. I.e., change

self._renderer.draw_image(
    gc,
    l * self._figdpi / self.dpi,
    (height-b-h) * self._figdpi / self.dpi,
    image)

to

self._renderer.draw_image(
    gc,
    l * self._figdpi / self.dpi,
    (height-b-h) * self._figdpi / self.dpi - 1,
    image)

Hopefully that might help someone track this down.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions