0
は、のカーソルの横にあるテキストをmatplotlibによって生成されたプロット内を移動するときに表示します。matplotlib:動的にテキスト位置を変更する
私はマウスモーションイベントを取得する方法を知っているが、どのように私は動的にテキスト要素の位置を変更のですか?
次のコードでは、カーソルの位置に応じてラインを配置する方法を示しています。
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
line = ax.plot([0, 1], [0,1])[0]
def on_mouse_move(event):
if None not in (event.xdata, event.ydata):
# draws a line from the center (0, 0) to the current cursor position
line.set_data([0, event.xdata], [0, event.ydata])
fig.canvas.draw()
fig.canvas.mpl_connect('motion_notify_event', on_mouse_move)
plt.show()
は、どのように私は、テキストと似た何かを行うことができますか?私はtext.set_data
を試しましたが、うまくいきませんでした。
はhttp://stackoverflow.com/questions/42446307/update-annotations-in-matplotlib-using-buttonsを参照してください。 – ImportanceOfBeingErnest