Issue 1:
Bug summary

In jupyter lab, the code snippet below sets the title of the axis to the x,y coords of a mouse click, however in matplotlib 3.5.2 specifically, the clicks aren't registered unless I'm clicking around using the pan or zoom controls of the interactive widget. Downgrading to matplotlib 3.5.1, the clicks are registered with just the cursor as expected with the same ipympl version 0.9.1.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
%matplotlib widget

fig, ax = plt.subplots(figsize=(5,5))
plt.plot(np.random.randint(0, 5, 5))
plt.show()

def onclick(event):
ax.set_title(f'x={event.x}, y={event.y}')
print(f'x={event.x}, y={event.y}')

fig.canvas.mpl_connect('button_press_event', onclick)

Actual outcome

No axis title after clicking inside the plot with just a regular cursor

Axis title set after clicking inside the plot with the pan tool of the interactive widget (same if using the zoom tool)

Expected outcome

This screenshot was taken with mpl version 3.5.1 where the regular cursor click was registered and the axis title was changed

Additional information

It's also interesting that under mpl 3.5.2, the cursor remains as the finger cursor icon after clicking while in mpl 3.5.1, the cursor icon changes back to the regular pointer - I'm not sure what that means but it is a difference in behavior...

Some relevant package versions:

matplotlib 3.5.2

ipympl 0.9.1

jupyterlab 3.4.3

Operating system

reproduced on both Ubuntu and macOS

Matplotlib Version

3.5.2

Matplotlib Backend

module://ipympl.backend_nbagg

Python version

3.8.13

Jupyter version

3.4.3

Installation

pip

Issue 2:
Bug summary

A regression between release versions 3.5.1 and 3.5.2 causes figures to fail to redraw after an initial plot is added using the pyplot interface in an interactive IPython session. This has been observed with both pyplot.plot and pyplot.tripcolor. The figure will show the first plot drawn, but subsequent calls to pyplot.plot and pyplot.tripcolor fail to update an on-screen figure until pyplot.draw is invoked. This has been observed with IPython versions 8.3.0 (current) and 8.2.0.

Both the Qt5 and Tk backends exhibit the same issues.

Code for reproduction

# Install matplotlib and ipython in a virtualenv
python3 -m venv ~/mpl.venv
. ~/mpl.venv/bin/activate
pip install matplotlib ipython

# Make sure to start with a clean config
mv ~/.ipython ~/.ipython.backup
mv ~/.config/matplotlib .config/matplotlib.backup

# Run `pylab`
ipython --pylab=tk

# ... the following are commands issues in the ipython prompt
plot(arange(10))
plot(-arange(10))
draw()

Actual outcome

After the first plot command, a figure appears with a y = x line shown.

After the second plot command, the figure does not update.

After the draw command, the figure updates to show both the y = x and y = -x lines.

Expected outcome

After the first plot command, a figure appears with a y = x line shown. (This is as expected.)

After the second plot command, the figure updates with the addition of a y = -x line. (This is the deviation.)

The draw command should produce no visible change in the figure.

Additional information

This regression has been bisected to commit f937b0a.

The testbed is a current Void Linux system running Python 3.10.4, including the system python3-tkinter package for a GUI. (As noted above, this bug is also present with the Qt5 backend.) All packages were installed in a virtual environment. The output of pip freeze is:

asttokens==2.0.5
backcall==0.2.0
cycler==0.11.0
decorator==5.1.1
executing==0.8.3
fonttools==4.33.3
ipython==8.3.0
jedi==0.18.1
kiwisolver==1.4.2
matplotlib==3.6.0.dev155+gf937b0ab5e
matplotlib-inline==0.1.3
numpy==1.22.3
packaging==21.3
parso==0.8.3
pexpect==4.8.0
pickleshare==0.7.5
Pillow==9.1.0
prompt-toolkit==3.0.29
ptyprocess==0.7.0
pure-eval==0.2.2
Pygments==2.12.0
pyparsing==3.0.9
python-dateutil==2.8.2
setuptools-scm==6.4.2
six==1.16.0
stack-data==0.2.0
tk==0.1.0
tomli==2.0.1
traitlets==5.2.0
wcwidth==0.2.5

(Note that the funny matplotlib version comes from a local git repo checked out to the problematic commit.)

Operating system

Void Linux x86_64

Matplotlib Version

3.5.2

Matplotlib Backend

TkAgg, Qt5Agg

Python version

3.10.4

Jupyter version

None

Installation

pip