ユーザーがmatplotlibのイベント処理を介してグラフを操作できるようにするスクリプトを作成しようとしていますが、ターミナルから追加情報を入力する必要があります
呼び出すraw_input()
とスクリプトが壊れているようで、RuntimeError: can't re-enter readline
エラーがスローされます
これを示す簡単なコードを次に示します。
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(np.random.rand(10))
def keypress(event):
print 'You press the "%s" key' %event.key
print 'is this true? Type yes or no'
y_or_n = raw_input()
cid = fig.canvas.mpl_connect('key_press_event', keypress)
plt.show()
これは、python を使用して実行すると正常に動作しますが、ipython --pylab を使用すると中断します。残念ながら、インタラクティブモードが必要です
他の人がこの問題を抱えているのを見ましたが、解決策を見たことはありません