`jupyter console` and matplotlib REPL integration

I’m trying to use jupyter console as a replacement for ipython on a linux system and I’m running into issues with the figure canvas.mpl_connect() method. In an interactive ipython session, I’m able to use mpl_connect to bind key_press_events to a callback function, but in jupyter console that doesn’t seem to work. Mpl “native” callbacks (like “`q” to close window) are dispatched, but a user-defined callback doesn’t seem to ever get triggered.

For example, when you %run the following script:

import matplotlib as mpl
import matplotlib.pyplot as plt

get_ipython().run_line_magic(‘gui’, ‘qt’)

mpl.use(‘QtAgg’)
plt.ion()

def kp(event):
print(‘keypress:’, event)

f = plt.figure()
f.canvas.mpl_connect(“key_press_event”, kp)

Under ipython, the kp() callback works, but not if you do the same in jupyter console. Doesn’t matter whether you’re using the Qt or the Tk backend.
I don’t fully understand how GUI event loop stuff intergrates with the jupyter kernel when running jupyter console, but was under the impression that things should be identical/similar to ipython.

Any advice or recommendations about how to do something like this properly would be appreciated.

TIA