Skip to content

Commit

Permalink
Set extent to preserve image aspect ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhi committed Oct 27, 2021
1 parent fdc3dfc commit 142b0c2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pip install mpl-image-labeller
- Uses keys instead of mouse
- Only depends on Matplotlib
- Works anywhere - from inside Jupyter to any supported GUI framework
- Displays images with correct aspect ratio
- Easily configurable keymap
- Smart interactions with default Matplotlib keymap

Expand Down
Binary file modified example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions mpl_image_labeller/_labeller.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from typing import List, Union

import numpy as np
from matplotlib.backend_bases import key_press_handler

# if TYPE_CHECKING:
from matplotlib.figure import Figure


Expand Down Expand Up @@ -114,7 +113,7 @@ def _get_image(i):

self._image_index = 0
self._ax = self._fig.add_subplot(111)
self._im = self._ax.imshow(self._get_image(0))
self._im = self._ax.imshow(self._get_image(0), aspect="equal")

# shift axis to make room for list of keybindings
box = self._ax.get_position()
Expand Down Expand Up @@ -202,7 +201,9 @@ def _update_title(self):
)

def _update_displayed(self):
self._im.set_data(self._get_image(self._image_index))
image = np.asarray(self._get_image(self._image_index))
self._im.set_data(image)
self._im.set_extent((-0.5, image.shape[1] - 0.5, image.shape[0] - 0.5, -0.5))
self._update_title()
self._fig.canvas.draw_idle()

Expand Down

0 comments on commit 142b0c2

Please sign in to comment.