<jupyter_start><jupyter_text>If you use the inline backend (i.e. %matplotlib inline), interactive features cannot work, because the plots are just png images.If you use the notebook backend (i.e. %matplotlib notebook) the interactive features do work, but the question would be where to print the result to. So in order to show the text one may add it to the figure as follows https://github.com/matplotlib/jupyter-matplotlib$ pip install ipympl$  If using the Notebook$ jupyter nbextension enable --py --sys-prefix ipympl     can be skipped for notebook version 5.3 and above$  If using JupyterLab$  Install nodejs: https://nodejs.org/en/download/$ jupyter labextension install @jupyter-widgets/jupyterlab-manager<jupyter_code>%matplotlib ipympl
# %matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(np.random.rand(10))
text=ax.text(0,0, "", va="bottom", ha="left")

def onclick(event):
    print('wth')
    tx = 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f' % (event.button, event.x, event.y, event.xdata, event.ydata)
    text.set_text(tx)

cid = fig.canvas.mpl_connect('button_press_event', onclick)
fig, ax = plt.subplots()
ax.plot(np.random.rand(10))

def onclick(event):
    print('%s click: button=%d, x=%d, y=%d, xdata=%f, ydata=%f' %
          ('double' if event.dblclick else 'single', event.button,
           event.x, event.y, event.xdata, event.ydata))

cid = fig.canvas.mpl_connect('button_press_event', onclick)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13040629095674966, 'fraction_numerical': 0.007208387942332897, 'mean_word_length': 4.697761194029851, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '624990', 'license': 'MIT', 'n_tokens_mistral': 535, 'n_tokens_neox': 526, 'n_words': 157, 'path': '_visualisations/matplotlib_ipympl.ipynb', 'repo_name': 'aixpact/data-science', 'size': '1526'}