1

I'm trying to draw a box on a scaled image, and I notice that when the image is very small, the box seems to be drawn with an offset (see second row of the image):

enter image description here

This behavior seems to be because I'm expecting the top left of the top left pixel to be aligned with the point (0, 0), but it seems that this point is actually aligned with the middle of the pixel. So, the coordinate of the top left corner of the image seems to actually be (-0.5, -0.5).

Is there a way to change the behavior of matplotlib.imshow so coordinates are aligned with the top left of each pixel instead of the centers?

3
  • Why don't you just subtract 0.5 from the box coordinates? Commented Apr 8, 2018 at 21:20
  • Because I'm a purist. I know how to subtract 0.5 from a number, but I'd like to learn how to use matplotlib better. Commented Jun 5, 2018 at 3:16
  • Feel free to provide a minimal reproducible example of the issue, such that people can understand what you're doing to create those plots and suggest an alternative. Commented Jun 5, 2018 at 9:25

1 Answer 1

2

The imshow extent is what you need.

Use extent=(0, numcols, 0, numrows) instead of the default (-0.5, numcols-0.5, -0.5, numrows-0.5).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.