2017-03-17 5 views
1

である私はPythonで)(plt.ionを使用しようとしている数字を更新可能:エラーをスローtight_layout:とValueErrorは:MAX()引数が空のシーケンス

import numpy as np 
import numpy.matlib 
import matplotlib.pyplot as plt 

plt.ion() 

plt.close('all') 

tmax =30 
W = np.random.rand(6,100)   

fig, ax = plt.subplots(2,3)  
plt.show() 

for t in range (1, tmax): 
    W = t * W   
    for ii in range(2): 
     for jj in range(3):  
      output = W[3*ii+jj,:].reshape((10,10),order = 'F') 
      ax[ii,jj].clear() 
      ax[ii,jj].imshow(output, interpolation='nearest')     
    plt.tight_layout() 
    plt.draw() 
    plt.pause(0.1) 


plt.waitforbuttonpress() 

これはコンソールで空白の数字が表示されます実行し、エラーを投げる:

Traceback (most recent call last):

File "", line 1, in runfile('/Users/Alessi/Documents/Spyder/3240ass/comp.py', wdir='/Users/Alessi/Documents/Spyder/3240ass')

File "/Users/Alessi/anaconda/lib/python3.5/site-packages/spyder/utils/site/sitecustomize.py", line 866, in runfile execfile(filename, namespace)

File "/Users/Alessi/anaconda/lib/python3.5/site-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "/Users/Alessi/Documents/Spyder/3240ass/comp.py", line 27, in plt.tight_layout()

File "/Users/Alessi/anaconda/lib/python3.5/site-packages/matplotlib/pyplot.py", line 1387, in tight_layout fig.tight_layout(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)

File "/Users/Alessi/anaconda/lib/python3.5/site-packages/matplotlib/figure.py", line 1752, in tight_layout rect=rect)

File "/Users/Alessi/anaconda/lib/python3.5/site-packages/matplotlib/tight_layout.py", line 322, in get_tight_layout_figure max_nrows = max(nrows_list)

ValueError: max() arg is an empty sequence

あなたがコンソールに(ion)インタラクティブ以上を使用することはできません

答えて

1

ps.usingアナコンダスパイダー。残念ながら、あなたが望むものについての質問はあまり明確ではありません。アニメーション化されたプロットをウィンドウに表示するとします。簡単な方法は、IPythonコンソールの外でスクリプトを実行することです。スパイダーでは、Run/Configure(またはF6キーを押す)に行き、「新しい専用のPythonコンソールで実行する」を選択します。

enter image description here

は今、スクリプト自体に問題はあなたが最初の呼び出し plt.show()、空のサブプロットを示しているということです。これは削除する必要があります。アニメーションを示すだろう

バージョンは次のようになり

import numpy as np 
import matplotlib.pyplot as plt 

plt.close('all') 
plt.ion() 

tmax =30 

fig, ax = plt.subplots(2,3)  

for t in range (1, tmax): 
    W = np.random.rand(6,100)  
    for ii in range(2): 
     for jj in range(3):  
      output = W[3*ii+jj,:].reshape((10,10),order = 'F') 
      ax[ii,jj].clear() 
      ax[ii,jj].imshow(output, interpolation='nearest') 
    if t == 1:     
     plt.tight_layout() 
    plt.draw() 
    plt.pause(0.1) 


plt.waitforbuttonpress() 
+0

私にとって重要な部分だった:「今、スクリプト自体に問題はあなたの最初の呼び出しplt.show()、空のサブプロットを示しているということです。これは削除する必要があります。 – Hakaishin

関連する問題