以下の内容はhttps://shuzo-kino.hateblo.jp/entry/2019/11/28/235836より取得しました。


matplotlibでキーアクションを受け取る

インタラクティブ編その2、キーボードの入力を受け取るやつです。
Arduinoなど外部機器を擬似キーボードとして繋げばグラフの切り替えなんかで楽できますね。

実際のところ

import sys
import numpy as np
import matplotlib.pyplot as plt


def press(event):
    print('press', event.key)
    sys.stdout.flush()
    if event.key == 'x':
        visible = xl.get_visible()
        xl.set_visible(not visible)
        fig.canvas.draw()

# Fixing random state for reproducibility
np.random.seed(19680801)


fig, ax = plt.subplots()

fig.canvas.mpl_connect('key_press_event', press)

ax.plot(np.random.rand(12), np.random.rand(12), 'go')
xl = ax.set_xlabel('easy come, easy go')
ax.set_title('Press a key')
plt.show()

f:id:shuzo_kino:20191129003807p:plain

$ python 002.py 
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
press u
press i



以上の内容はhttps://shuzo-kino.hateblo.jp/entry/2019/11/28/235836より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14