prompt-toolkit / ptpython

A better Python REPL
BSD 3-Clause "New" or "Revised" License
5.22k stars 278 forks source link

ptipython doesn't work #319

Open lusu2004 opened 5 years ago

lusu2004 commented 5 years ago
  1. anaconda for python 3.7
  2. pip install ptpython
  3. ptipython
  4. input below command %pylab #it will use matplotlib backend: Qt5Agg x = np.linspace(0,6,1000) y= np.sin(x) plt.plot(x,y)

the Figure1 window rised, but show nothing.

Thanks

yamsu commented 4 years ago

Yes I can confirm this. However, the same lines of code are working fine in vanilla ipython. In ptipython both magic function %pylab and %matplotlib cause the same error

%pylab # Figure is blank
%matplotlib # Figure is blank

Working! with show(block=True) Following the plt.plot command with

%pylab
x = np.linspace(0,6,1000)
y= np.sin(x)
plt.plot(x,y)
show(block=True)

plot figure is rendered as expected.

Using matplotlib directly without the magic functions, works!

import matplotlib
matplotlib.use('Qt5Agg',warn=False, force=True)
from matplotlib import pyplot as plt
plt.plot([1,2,3],[1,2,3])
plt.show()

The issue seems to be related to non-blocking show command under ptipython. Figure shows nothing with the following:

import matplotlib
matplotlib.use('Qt5Agg',warn=False, force=True)
from matplotlib import pyplot as plt
plt.plot([1,2,3],[1,2,3])
plt.show(block=False)
yamsu commented 4 years ago

This seems to be an old issue. Please refer to issues #20 #221

From a cursory reading its looks like the issue is with the event loops for ptipthon and ipython.