2017-03-17 2 views
1

입니다 :이 오류가 발생 tight_layout : ValueError를이 : 최대() 인수가() 파이썬에서 그림 업데이트 있도록 내가 plt.ion를 사용하여 노력하고 있어요 빈 순서

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