2013-04-08 30 views
7

私はmatplotlibで2D配列をプロットしています。ウィンドウの右下隅にカーソルのxとy座標が表示されます。このステータスバーにカーソル下のデータに関する情報を追加するにはどうしたらいいですか?たとえば 'x = 439.501 y = 317.744'の代わりに 'x、y:[440,318] data:100'と表示されますか?何とかこのナビゲーションツールバーに手を差し伸べて自分のメッセージを書いて表示できますか?matplotlibに情報を追加するナビゲーションツールバー/ステータスバー?

私は 'button_press_event'のために独自のイベントハンドラを追加することができました。データ値がターミナルウィンドウに表示されるようになっていますが、この方法では多くのマウスクリックと対話セッションのフラッディングが必要です。

+0

可能重複(HTTP:// stackoverflowの。 com/questions/14754931/matplotlib-values-under-cursor) – tacaswell

+0

http://stackoverflow.com/questions/14349289/in-a-matplotlib-figure-window-with-imshow-how-can-i-remove-すべてのグーグルの後に – tacaswell

答えて

10

ax.format_coordを再割り当てするだけで、そのラベルを描画するためのコールバックが必要です。

は、ドキュメントからthis exampleを参照、ならびに In a matplotlib figure window (with imshow), how can I remove, hide, or redefine the displayed position of the mouse?matplotlib values under cursor

(コード例から直接持ち上げ)カーソルの下matplotlibの値]の

""" 
Show how to modify the coordinate formatter to report the image "z" 
value of the nearest pixel given x and y 
""" 
import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.cm as cm 

X = 10*np.random.rand(5,3) 

fig = plt.figure() 
ax = fig.add_subplot(111) 
ax.imshow(X, cmap=cm.jet, interpolation='nearest') 

numrows, numcols = X.shape 
def format_coord(x, y): 
    col = int(x+0.5) 
    row = int(y+0.5) 
    if col>=0 and col<numcols and row>=0 and row<numrows: 
        z = X[row,col] 
        return 'x=%1.4f, y=%1.4f, z=%1.4f'%(x, y, z) 
    else: 
        return 'x=%1.4f, y=%1.4f'%(x, y) 

ax.format_coord = format_coord 
plt.show() 
+0

を非表示または再定義すると、私はまだこれを見つけられませんでした!ソリューションをありがとう! – northaholic

+0

@northaholicこれで問題を解決できれば(左の大きいグレーのチェックマーク) – tacaswell

関連する問題