|
|
|||||||||||||||||||||||||||||
|
event_handling_Examples 04_idle_and_timeout. |
H.Kamifuji . |
|
Demonstrate/test the idle and timeout API 警告:idle_event は推奨されていません。 代わりにアニメーションモジュールを使用してください。 これはこれまでの gtk でしかテストされておらず、プロトタイプの実装です
from __future__ import print_function
"""
Demonstrate/test the idle and timeout API
WARNING: idle_event is deprecated. Use the animations module instead.
This is only tested on gtk so far and is a prototype implementation
"""
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
t = np.arange(0.0, 2.0, 0.01)
y1 = np.sin(2*np.pi*t)
y2 = np.cos(2*np.pi*t)
line1, = ax.plot(y1)
line2, = ax.plot(y2)
N = 100
def on_idle(event):
on_idle.count += 1
print('idle', on_idle.count)
line1.set_ydata(np.sin(2*np.pi*t*(N - on_idle.count)/float(N)))
event.canvas.draw()
# test boolean return removal
if on_idle.count == N:
return False
return True
on_idle.cid = None
on_idle.count = 0
fig.canvas.mpl_connect('idle_event', on_idle)
plt.show()
|
![]() Python 3.11.2 見直しました。上記のコードでは、下記のエラーが発生します。 Traceback (most recent call last): File "_:\idle_and_timeout.py", line 35, in <module> fig.canvas.mpl_connect('idle_event', on_idle) File "C:\Users\_____\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\backend_bases.py", line 2476, in mpl_connect return self.callbacks.connect(s, func) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\_____\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\cbook\__init__.py", line 224, in connect _api.check_in_list(self._signals, signal=signal) File "C:\Users\_____\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\_api\__init__.py", line 131, in check_in_list raise ValueError(msg) ValueError: 'idle_event' is not a valid value for signal; supported values are 'resize_event', 'draw_event', 'key_press_event', 'key_release_event', 'button_press_event', 'button_release_event', 'scroll_event', 'motion_notify_event', 'pick_event', 'figure_enter_event', 'figure_leave_event', 'axes_enter_event', 'axes_leave_event', 'close_event' matplotlib 内部のエラーのようです。matplotlib の改修(先祖帰りバグの改修)を待つしかない。 Python 3.11.6 (matplotlib 3.7.1) では、下記のようなエラーがあり、実行できない。 Traceback (most recent call last): File "M:\______\idle_and_timeout.py", line 35, inPython 3.12.0 (matplotlib 3.8.1) では、下記のようなエラーがあり、実行できない。 Traceback (most recent call last): File "E:\______\idle_and_timeout.py", line 35, in新しいサンプルは、見つかりません。 gtk と共に、消え去るのか? |
| event_handling_Examples code: idle_and_timeout.py |
|