0

plotting under spyder 4 (and also after downgrading with 3) doesn't work. I am just doing:

data=[1,2,3]
plt.plot(data)

The output is a non-responding frame: enter image description here After forcing to close it, i get:

An error ocurred while starting the kernel
RROR:tornado.application:Exception in callback functools.partial(.advance_eventloop at 0x000001A802791318>)
Traceback (most recent call last):
File "path\anaconda3\lib\site‑packages\tornado\ioloop.py", line 743, in _run_callback
ret = callback()
File "path\anaconda3\lib\site‑packages\ipykernel\kernelbase.py", line 310, in advance_eventloop
eventloop(self)
File "path\anaconda3\lib\site‑packages\ipykernel\eventloops.py", line 232, in loop_tk
app.tk.createfilehandler(stream.getsockopt(zmq.FD), READABLE, notifier)
AttributeError: '_tkinter.tkapp' object has no attribute 'createfilehandler'

(where is replaced with path) Any idea why?

(if relevant i am using windows, python3)

Edit

adding plt.show() alone doesn't make a difference to the output (still blank frame), but thanks to Neven V. and other quests i added

root = tk.Tk()

def on_closing():
    if messagebox.askokcancel("Quit", "Do you want to quit?"):
        root.destroy()

root.protocol("WM_DELETE_WINDOW", on_closing)
root.mainloop()

then i see a plot where the frame is responding. But after clicking on quit, the process do not quit and i have to restart the kernel (the mainloop is halting it but without it i get the result: no plot), thus i tried:

plt.show(block=False)
plt.pause(0.001) # Pause for interval seconds.
input("hit[enter] to end.")
plt.close('all') # all open plots are correctly closed after each run

and see a plot but it is non responding also after hitting enter.

Carlos Cordoba
  • 33,273
  • 10
  • 95
  • 124
user23657
  • 131
  • 1
  • 2
  • 11
  • 1
    Did you `plt.show()` ? That could solve the blank window. As for the error message upon closing, I think that's pretty much unavoidable unless you specify what to do on close event. (`on_closing`). Maybe https://stackoverflow.com/questions/111155/how-do-i-handle-the-window-close-event-in-tkinter will help – Neven V. Mar 28 '20 at 06:52
  • thanks, i tried to adapt https://stackoverflow.com/questions/111155/how-do-i-handle-the-window-close-event-in-tkinter and see a plot but as described in the edit the process don't quit – user23657 Mar 28 '20 at 09:08
  • 1
    I did some tests, and with my setup (Python 3.6.9, Ubuntu 18.04), it turns out that : (1) closing a `plt` window doesn't trigger an error. (2) a `Tk` window can be closed without issue when the snippet `root = tk.Tk() [...] root.mainloop()` is entered and (3) `plt.show()` is enough for a plot to appear. Unless I have more information about your code, I'm afraid I can't help you. As far as I understand, Spyder is not directly involved in plotting, does anything work differently if you execute the code outside of Spyder ? – Neven V. Mar 28 '20 at 11:07
  • 1
    The traceback you posted above seems to indicate a bug in ipykernel. What's your Python version? – Carlos Cordoba Mar 28 '20 at 17:50
  • at Neven the code is only the two lines + tk, @Carlos i have python 3.7 – user23657 Mar 28 '20 at 18:55
  • in idle with together with plt.show() the plot occurs, but not in spyder – user23657 Mar 29 '20 at 09:21
  • @carlos i have submitted a bug to github, there you closed it and said it would be gone in 4.1.2, i have Spyder 4.1.2 and the bug ist still present, would be nice if the you could have a look again on the issue – user23657 Apr 08 '20 at 13:06
  • The bug on the Spyder side was fixed in our 4.1.2 version. However, this is a bug in the `ipykernel` package (I said it already above), so it's out of our control. Please report it there. – Carlos Cordoba Apr 08 '20 at 17:56

1 Answers1

0

I was using a standalone Python (3.8.3) within Spyder (IPython 7.15.0), but it resolved when I reverted to the conda installation (Python 3.6.8, IPython 7.6.0). I'm not sure that helps though!

AliShipman
  • 21
  • 4