Search code examples
python-3.xmatplotlib

how to hide x and y values of matplotlib figure while mouse hover


As you know in matplotlib plot, it shows a value for x and a value for y while hovering the mouse on plots (the red border in the picture below).

Is there any way to hide them and make plt not to show them at all? So the figure does not show the values after mouse hovers on plot.

# just a simple code
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [1, 2, 3, 4]
plt.plot(x, y)
plt.show()

enter image description here


Solution

  • You can reassign the callback function that displays the coordinates (ax.format_coord) to a function that outputs an empty string:

    from matplotlib import pyplot as plt
    import numpy as np
    
    plt.scatter(np.random.rand(20), np.random.rand(20))
    plt.gca().format_coord = lambda x,y: ""
    plt.show()
    

    This example uses the function to show pixel values.