Skip to content

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

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
aerusso opened this issue Jul 24, 2020 · 1 comment

Comments

@aerusso
Copy link

aerusso commented Jul 24, 2020

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.

@QuLogic
Copy link
Member

QuLogic commented Jul 24, 2020

Duplicate of #6827; i.e., raising DPI fixes the gap.

@QuLogic QuLogic closed this as completed Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants