您只需重新指定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