8000 Incorrect behaviour: plt.show(block=True) with qt5 and jupyter · Issue #13302 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Incorrect behaviour: plt.show(block=True) with qt5 and jupyter #13302
Closed as not planned
@vdrhtc

Description

@vdrhtc

Bug report

Bug summary

I'm implementing live plotting for our data acquisition system using Jupyter and FuncAnimation, and have just found an interesting defect in plt.show(block=True) behaviour.

Precisely, it does not unblock when the plot window is closed, and sending KeyboardInterrupt crashes the kernel.

I was able to accidentally fix the first part by modifying the show() function in backend_bases.py based on this forum reply (basically, by not calling manager.canvas.figure.show() when block is not None, and instead callingmanager.window.setVisible(True) just before cls.mainloop() since it calls Qt's exec() that should call show() by itself)

The second issue persists, though.

Code for reproduction

%pylab qt5
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
fig, ax = plt.subplots()
xdata, ydata = [], []
ln, = plt.plot([], [], 'ro')

def init():
    ax.set_xlim(0, 2*np.pi)
    ax.set_ylim(-1, 1)
    return ln,

def update(frame):
    xdata.append(frame)
    ydata.append(np.sin(frame))
    ln.set_data(xdata, ydata)
    return ln,

ani = FuncAnimation(fig, update, frames=np.linspace(0, 2*np.pi, 128),
                    init_func=init, blit=True, interval = 50)

plt.show(block=True)

Actual outcome

Plot window that can be closed by either pressing the corresponding window button or by sending KeyboardInterrupt. The kernel then should be freed.

Expected outcome

The kernel is not freed upon closing (without my fix) and dies on KeyboardInterrupt.

Matplotlib version

  • Operating system: 4.18.16-100.fc27.x86_64
  • Matplotlib version: 3.0.2
  • Matplotlib backend: Qt5Agg
  • Python version: 3.6
  • IPython: 7.2.0
  • Jupyter notebook: 5.7.4

Everything installed with pip in a virtualenv.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GUI: Qtstatus: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.status: inactiveMarked by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0