interactive-figure 0.3.5__py3-none-any.whl → 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- interactive_figure/__about__.py +1 -1
- interactive_figure/interactive_figure.py +42 -26
- {interactive_figure-0.3.5.dist-info → interactive_figure-0.4.0.dist-info}/METADATA +1 -1
- interactive_figure-0.4.0.dist-info/RECORD +7 -0
- interactive_figure-0.3.5.dist-info/RECORD +0 -7
- {interactive_figure-0.3.5.dist-info → interactive_figure-0.4.0.dist-info}/WHEEL +0 -0
- {interactive_figure-0.3.5.dist-info → interactive_figure-0.4.0.dist-info}/licenses/LICENSE.txt +0 -0
interactive_figure/__about__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.
|
|
1
|
+
__version__ = "0.4.0"
|
|
@@ -7,19 +7,20 @@ Source: https://github.com/teuncm/interactive-figure
|
|
|
7
7
|
|
|
8
8
|
import matplotlib.pyplot as plt
|
|
9
9
|
from types import SimpleNamespace
|
|
10
|
+
import sys
|
|
10
11
|
|
|
11
12
|
|
|
12
|
-
def create(
|
|
13
|
+
def create(hide_labels=False, hide_toolbar=False, **kwargs):
|
|
13
14
|
"""Create the interactive figure.
|
|
14
15
|
|
|
15
16
|
Parameters
|
|
16
17
|
----------
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
hide_labels : bool, optional
|
|
19
|
+
remove all labels from the figure (makes rendering *much* faster).
|
|
19
20
|
hide_toolbar : bool, optional
|
|
20
21
|
whether to hide the toolbar, default False.
|
|
21
22
|
|
|
22
|
-
Remaining arguments will be sent to the figure upon creation.
|
|
23
|
+
Remaining keyword arguments will be sent to the figure upon creation.
|
|
23
24
|
|
|
24
25
|
Raises
|
|
25
26
|
----------
|
|
@@ -30,6 +31,9 @@ def create(aspect_ratio="auto", hide_toolbar=False, **kwargs):
|
|
|
30
31
|
if hide_toolbar:
|
|
31
32
|
plt.rcParams["toolbar"] = "None"
|
|
32
33
|
|
|
34
|
+
if hide_labels:
|
|
35
|
+
_state.hide_labels = True
|
|
36
|
+
|
|
33
37
|
# Disable interactive mode for explicit control over drawing. See:
|
|
34
38
|
# https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.isinteractive.html#matplotlib.pyplot.isinteractive
|
|
35
39
|
plt.ioff()
|
|
@@ -38,7 +42,6 @@ def create(aspect_ratio="auto", hide_toolbar=False, **kwargs):
|
|
|
38
42
|
fig.canvas.manager.set_window_title("Interactive Figure")
|
|
39
43
|
# Create drawable axis.
|
|
40
44
|
_state.ax = ax = plt.gca()
|
|
41
|
-
ax.set_aspect(aspect_ratio)
|
|
42
45
|
|
|
43
46
|
# Show figure but allow the main thread to continue.
|
|
44
47
|
plt.show(block=False)
|
|
@@ -57,10 +60,11 @@ def create(aspect_ratio="auto", hide_toolbar=False, **kwargs):
|
|
|
57
60
|
fig.canvas.mpl_disconnect(fig.canvas.manager.button_press_handler_id)
|
|
58
61
|
fig.canvas.mpl_connect("key_press_event", _key_press_handler)
|
|
59
62
|
fig.canvas.mpl_connect("button_press_event", _button_press_handler)
|
|
63
|
+
fig.canvas.mpl_connect("close_event", _close_handler)
|
|
60
64
|
|
|
61
|
-
print("
|
|
65
|
+
print("Interactive figure: created")
|
|
62
66
|
else:
|
|
63
|
-
raise RuntimeError("
|
|
67
|
+
raise RuntimeError("Interactive figure: ERROR - you cannot create multiple figures")
|
|
64
68
|
|
|
65
69
|
|
|
66
70
|
def draw():
|
|
@@ -75,26 +79,17 @@ def draw():
|
|
|
75
79
|
canvas.flush_events()
|
|
76
80
|
|
|
77
81
|
|
|
78
|
-
def clear(
|
|
79
|
-
"""Reset contents and layout of the figure.
|
|
80
|
-
|
|
81
|
-
Parameters
|
|
82
|
-
----------
|
|
83
|
-
set_limits : bool, optional
|
|
84
|
-
set the Axes limits to [0, 100].
|
|
85
|
-
hide_labels : bool, optional
|
|
86
|
-
remove all labels from the figure.
|
|
87
|
-
"""
|
|
82
|
+
def clear():
|
|
83
|
+
"""Reset contents and layout of the figure."""
|
|
88
84
|
_check_exists()
|
|
89
85
|
|
|
90
86
|
ax = _state.ax
|
|
91
87
|
ax.clear()
|
|
92
88
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
ax.set_ylim([0, 100])
|
|
89
|
+
ax.set_xlim([0, 100])
|
|
90
|
+
ax.set_ylim([0, 100])
|
|
96
91
|
|
|
97
|
-
if hide_labels:
|
|
92
|
+
if _state.hide_labels:
|
|
98
93
|
ax.set_xticks([])
|
|
99
94
|
ax.set_yticks([])
|
|
100
95
|
|
|
@@ -110,13 +105,13 @@ def close():
|
|
|
110
105
|
"""Close the figure."""
|
|
111
106
|
_check_exists()
|
|
112
107
|
|
|
108
|
+
_state.closed_using_ui = False
|
|
113
109
|
plt.close(_state.fig)
|
|
114
110
|
|
|
111
|
+
# Handle proper closure so that the figure can be reused.
|
|
115
112
|
_state_reset_fig()
|
|
116
113
|
_state_reset_press()
|
|
117
114
|
|
|
118
|
-
print("Successfully closed the interactive figure.")
|
|
119
|
-
|
|
120
115
|
|
|
121
116
|
def wait_for_interaction(timeout=-1):
|
|
122
117
|
"""Wait for interaction.
|
|
@@ -166,7 +161,7 @@ def wait_for_interaction(timeout=-1):
|
|
|
166
161
|
interaction_type = None if event is None else event.name == "key_press_event"
|
|
167
162
|
|
|
168
163
|
if interaction_type is None:
|
|
169
|
-
# No button was pressed, so reset the state.
|
|
164
|
+
# No button was pressed, so reset the press state.
|
|
170
165
|
_state_reset_press()
|
|
171
166
|
|
|
172
167
|
return interaction_type
|
|
@@ -235,7 +230,7 @@ def wait(timeout):
|
|
|
235
230
|
_check_exists()
|
|
236
231
|
|
|
237
232
|
_state.fig.canvas.start_event_loop(timeout=timeout)
|
|
238
|
-
#
|
|
233
|
+
# Reset the press state.
|
|
239
234
|
_state_reset_press()
|
|
240
235
|
|
|
241
236
|
|
|
@@ -262,13 +257,15 @@ def _check_exists():
|
|
|
262
257
|
If the figure is not available
|
|
263
258
|
"""
|
|
264
259
|
if _state.fig is None:
|
|
265
|
-
raise RuntimeError("
|
|
260
|
+
raise RuntimeError("Interactive figure: ERROR - figure is not available")
|
|
266
261
|
|
|
267
262
|
|
|
268
263
|
def _state_reset_fig():
|
|
269
264
|
"""Reset figure information."""
|
|
270
265
|
_state.fig = None
|
|
271
266
|
_state.ax = None
|
|
267
|
+
_state.hide_labels = False
|
|
268
|
+
_state.closed_using_ui = True
|
|
272
269
|
|
|
273
270
|
|
|
274
271
|
def _state_reset_press():
|
|
@@ -307,10 +304,29 @@ def _button_press_handler(event):
|
|
|
307
304
|
_state.last_mouse_y = event.ydata
|
|
308
305
|
|
|
309
306
|
|
|
307
|
+
def _close_handler(event):
|
|
308
|
+
"""Exit when the user presses the red x to close the figure
|
|
309
|
+
to prevent an infinite event loop.
|
|
310
|
+
|
|
311
|
+
Parameters
|
|
312
|
+
----------
|
|
313
|
+
event
|
|
314
|
+
The event object that was generated internally
|
|
315
|
+
"""
|
|
316
|
+
print("Interactive figure: closed")
|
|
317
|
+
|
|
318
|
+
# Triggered if the UI ('the red x') is used to close the figure.
|
|
319
|
+
if _state.closed_using_ui:
|
|
320
|
+
print("Interactive figure: exited script")
|
|
321
|
+
sys.exit(0)
|
|
322
|
+
|
|
323
|
+
|
|
310
324
|
# Namespace to track the internal state of the interactive figure.
|
|
311
325
|
_state = SimpleNamespace(
|
|
312
326
|
fig=None,
|
|
313
327
|
ax=None,
|
|
328
|
+
hide_labels=False,
|
|
329
|
+
closed_using_ui=True,
|
|
314
330
|
last_keypress=None,
|
|
315
331
|
last_mousepress=None,
|
|
316
332
|
last_mouse_x=None,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: interactive-figure
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Create interactive Matplotlib figures!
|
|
5
5
|
Project-URL: Documentation, https://teuncm.github.io/interactive-figure/autoapi/interactive_figure/interactive_figure/index.html
|
|
6
6
|
Project-URL: Issues, https://github.com/teuncm/interactive-figure/issues
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interactive_figure/__about__.py,sha256=Vx47i8QNeXJNuUzstqWuU6eCWE5xtaY0kgN-Gm_d_gE,23
|
|
2
|
+
interactive_figure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
interactive_figure/interactive_figure.py,sha256=EY2rRb0Aq7PAgarTlxVg3A4rHKcNizTVjXsvPRm2sGc,8911
|
|
4
|
+
interactive_figure-0.4.0.dist-info/METADATA,sha256=8SjDmwJW0emC8m3XhQRcRRpl7BLai1_qRieT514-Vrk,2438
|
|
5
|
+
interactive_figure-0.4.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
6
|
+
interactive_figure-0.4.0.dist-info/licenses/LICENSE.txt,sha256=R6IpPdPKA5nLHPKRXIhlFHLE59dMUtve0qeXhZPr0Hk,1043
|
|
7
|
+
interactive_figure-0.4.0.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
interactive_figure/__about__.py,sha256=hu_23GWCWpKjdw97-0y_O7JlxUWN4apUKOL4q5xXd7Q,23
|
|
2
|
-
interactive_figure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
interactive_figure/interactive_figure.py,sha256=hvQX5OACBYoz5EK9Wd3aOZm6I79ia6PGg69CtkPl_Mo,8410
|
|
4
|
-
interactive_figure-0.3.5.dist-info/METADATA,sha256=WYQ6OrtTdjiUS3npBEhymGvE5Fc2Pc7PxLBPGCYr-4U,2438
|
|
5
|
-
interactive_figure-0.3.5.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
6
|
-
interactive_figure-0.3.5.dist-info/licenses/LICENSE.txt,sha256=R6IpPdPKA5nLHPKRXIhlFHLE59dMUtve0qeXhZPr0Hk,1043
|
|
7
|
-
interactive_figure-0.3.5.dist-info/RECORD,,
|
|
File without changes
|
{interactive_figure-0.3.5.dist-info → interactive_figure-0.4.0.dist-info}/licenses/LICENSE.txt
RENAMED
|
File without changes
|