LoginSignup
2
1

More than 5 years have passed since last update.

matplotlibでキーボード入力を受け付ける際のメモ

Posted at

ひっかかったところ

matplotlib.pyplot.connect('key_press_event',function)でキーボードが押された時の処理を実行できる。その際qキーで判定させたところ、プログラムが終了するようなコードを書いていないにもかかわらずプログラムが終了した。

↓以下プログラム例

import matplotlib.pyplot as plt

def onKey(event):
    if event.key = 'q':
        print("q is pressed")
        plt.plot()               # この処理が終わり次第プログラムも終了する 
...

plt.connect('key_press_event',onKey)

解決策

matplotlibではqが押された場合プログラムを終了させるように定義されている(?)
とりあえず他のキーで代用したところ、プログラムが勝手に終了しなくなった。
(詳しい方は教えてもらえると助かります・・・)

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1