-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from ianhi/callbacks
Callbacks
- Loading branch information
Showing
20 changed files
with
201 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,3 +153,5 @@ cython_debug/ | |
|
||
## vscode | ||
.vscode | ||
|
||
docs/examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
--------- | ||
Callbacks | ||
--------- | ||
Demonstration of how to set up callback functions. | ||
""" | ||
|
||
from typing import Tuple | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
from mpl_point_clicker import clicker | ||
|
||
image = np.load("example_image.npy") | ||
|
||
fig, ax = plt.subplots() | ||
ax.imshow(image, cmap='gray') | ||
klicker = clicker(ax, ['cells', 'pdms', 'media'], markers=['o', 'x', '*']) | ||
|
||
|
||
def class_changed_cb(new_class: str): | ||
print(f'The newly selected class is {new_class}') | ||
|
||
|
||
def point_added_cb(position: Tuple[float, float], klass: str): | ||
x, y = position | ||
print(f"New point of class {klass} added at {x=}, {y=}") | ||
|
||
|
||
def point_removed_cb(position: Tuple[float, float], klass: str, idx): | ||
x, y = position | ||
|
||
suffix = {1: 'st', 2: 'nd', 3: 'rd'}.get(idx, 'th') | ||
print( | ||
f"The {idx}{suffix} point of class {klass} with position {x=:.2f}, {y=:.2f} was removed" | ||
) | ||
|
||
|
||
klicker.on_class_changed(class_changed_cb) | ||
klicker.on_point_added(point_added_cb) | ||
klicker.on_point_removed(point_removed_cb) | ||
|
||
|
||
plt.show() | ||
|
||
|
||
print(klicker.get_positions()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.