We're updating the default styles for Matplotlib 2.0

Learn what to expect in the new updates


Previous topic

event_handling example code: resample.py

Next topic

event_handling example code: timers.py

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)