You are reading an old version of the documentation (v1.4.0). For the latest version see

Previous topic

event_handling example code:

Next topic

event_handling example code:

This Page

event_handling example code: test_mouseclicks.pyΒΆ

[source code]

#!/usr/bin/env python
from __future__ import print_function

import matplotlib
import matplotlib.pyplot as plt

#print("***** TESTING WITH BACKEND: %s"%matplotlib.get_backend() + " *****")

def OnClick(event):
    if event.dblclick:
        print("DBLCLICK", event)
        print("DOWN    ", event)

def OnRelease(event):
    print("UP      ", event)

fig = plt.gcf()
cid_up = fig.canvas.mpl_connect('button_press_event', OnClick)
cid_down = fig.canvas.mpl_connect('button_release_event', OnRelease)

plt.gca().text(0.5, 0.5, "Click on the canvas to test mouse events.",
               ha="center", va="center")

Keywords: python, matplotlib, pylab, example, codex (see Search examples)