Open Freed-Wu opened 2 years ago
This is another example:
# Use qt5agg by default
from matplotlib import pyplot as plt
fig, ax = plt.subplots()
ax.plot(range(3))
fig.show()
In python
, a window will be opened normally. In ptpython
, the result is matplotlib is not responding
and window collapsed.
I have no idea what the consequences of the change in https://github.com/ssiegel/ptpython/commits/matplotlib-interactive are (changing from in_thread=True
to in_thread=False
in particular), so I won't open a pull request for now. But it seems to work fine for me. Also on the linked branch is a second commit that integrates the PySide6 Qt event loop, so the QtAgg Backend can be used interactively as well.
We need to run the (Tkinter, Qt) event loops from the main thread because that's where Matplotlib creates the GUI. It should be possible to run the event loops while prompt_toolkit.application.Application.run(in_thread=True)
is doing its job in a separate thread. But unfortunately the call is blocking, so to do anything on the main thread we would have to change that function.
Related issue: https://github.com/matplotlib/matplotlib/issues/24968
Reproduce Procedures
The screen will be blank and crash.
However, if
then input the same python code. matplotlib will work normally.
This example refer to https://matplotlib.org/stable/tutorials/introductory/usage.html#what-is-interactive-mode.
Environment