您只需重新指定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()
可能重複(HTTP://計算器。 com/questions/14754931/matplotlib-values-under-cursor) – tacaswell 2013-04-08 14:10:32
也http://stackoverflow.com/questions/14349289/in-a-matplotlib-figure-window-with-imshow-how-can-i-remove-隱藏或重新定義 – tacaswell 2013-04-08 14:11:21