简体   繁体   中英

Why does my plot freeze/not show in matplotlib outside of Spyder

So I have the following code:

import matplotlib.pyplot as plt
import numpy as np
from matplotlib import colors

plt.ion()

example_data = np.random.randint(5, size=(44,80))
cmap = colors.ListedColormap(['black','white','green','blue','red'])
bounds = [0,1,2,3,4,5]
norm = colors.BoundaryNorm(bounds, cmap.N)

img = plt.imshow(example_data, interpolation='nearest',origin='lower',cmap=cmap, norm=norm)
plt.draw()

If I run this with the backend in matplotlibrc set to Qt4Agg, I get the plot appearing but the window is 'Not responding' and needs to be forced to close.

If I run it with the backend set to GTK3Agg (Which is what I'm aiming for really) I get a blank plot window with no plot on it and the message 'python.exe has stopped working'

If I run it within Spyder then it all works fine (Backend is Qt4Agg here I think). I get exactly what I want and no freezing/unresponsiveness.

Could anyone help? I think I'm not fully understanding the interactive issues with running it outside of the IDE.

Thanks.

EDIT: Error log is:

Traceback (most recent call last)
  File"<string>", line 73, in execInThread
  File"<string>", line 44, in __call__
  File"C:\Program Files\PyScripter\Lib\rpyc.zip\rpyc\core\netref.py", line 196, in __call__
  File"C:\Program Files\PyScripter\Lib\rpyc.zip\rpyc\core\netref.py", line 71, in syncerq
  File"C:\Program Files\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py", line 431, in sync_request
  File"C:\Program Files\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py", line 379, in serve
  File"C:\Program Files\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py", line 337, in _recv
  File"C:\Program Files\PyScripter\Lib\rpyc.zip\rpyc\core\channel.py", line 50, in recv
  File"C:\Program Files\PyScripter\Lib\rpyc.zip\rpyc\core\stream.py", line 166, in read
EOFError: [WinError 10054] An existing connection was forcibly closed by the remote host

EDIT2:

So looking in the Windows Event viewer logs I can see I get:

ERROR - APPLICATION ERROR:

Faulting Application name:python.exe, version 0.0.0.0, time stamp: 0x54f9ed12
Faulting module name: libcairo-2.dll, version 0.0.0.0, time stamp 0x50a184bb
Exception code: 0xc0000005
Fault offset: 0x00023024
Faulting process id: 0xca8
Faulting application start time: 0x01d1f7a6ba424ee5
Faulting application path: C:\Anaconda3\python.exe
Faulting module path: C:\Anaconda3\Lib\site-packages\GTK+-Bundle-3.6.1\bin\libcairo-2.dll
Report Id: ff7c449c-6399-11e6-ba70-0cc47a6a54fd

So maybe it's something to do with the libcairo-2.dll? I reinstalled GTK to see if that helped but appears to have made no difference.

在PyScripter 2.7.10的菜单Run-> Python engine - > Internal中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM