Skip to content
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

Callbacks #8

Merged
merged 9 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,5 @@ cython_debug/

## vscode
.vscode

docs/examples
2 changes: 1 addition & 1 deletion docs/Contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Now clone your fork of the Git repository and make an editable (``-e``) install.

git clone <your fork>
cd mpl-point-clicker
pip install -e ".[dev]"
pip install -e ".[test, doc]"


Working with Git
Expand Down
54 changes: 0 additions & 54 deletions docs/examples/example.ipynb

This file was deleted.

23 changes: 0 additions & 23 deletions docs/examples/example.py

This file was deleted.

1 change: 0 additions & 1 deletion docs/examples/example.py.md5

This file was deleted.

101 changes: 0 additions & 101 deletions docs/examples/example.rst

This file was deleted.

Binary file removed docs/examples/example_codeobj.pickle
Binary file not shown.
Binary file removed docs/examples/examples_jupyter.zip
Binary file not shown.
Binary file removed docs/examples/examples_python.zip
Binary file not shown.
Binary file removed docs/examples/images/sphx_glr_example_001.png
Binary file not shown.
Binary file not shown.
62 changes: 0 additions & 62 deletions docs/examples/index.rst

This file was deleted.

12 changes: 0 additions & 12 deletions docs/examples/sg_execution_times.rst

This file was deleted.

50 changes: 50 additions & 0 deletions examples/callbacks.py
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())
3 changes: 1 addition & 2 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
Basic Usage
-----------

A short example showcasing how to use the library. The docstrings will be
turns in REST by sphinx-gallery.
A short example showcasing how to use the library.
"""

import matplotlib.pyplot as plt
Expand Down
Loading