2016-06-13 2 views
5

I가 내가 pivot_table을 사용하여 생성 된 다음 dataframe : boxplot 여러에에 ValueError : NUM이어야합니다 (1) <= NUM ​​<= 2가 아닌 3

enter image description here

을하고 난 다음 코드를 사용하고 있습니다 열 :

01,231,475,556,825,799,425 :

fig = plt.figure() 
for i in range(0,25): 
    ax = plt.subplot(1,2,i+1) 
    toPlot1.boxplot(column='Score',by=toPlot1.columns[i+1],ax=ax) 
fig.suptitle('test title', fontsize=20) 
plt.show() 

나는 다음과 같은 출력을 기다리고 있었다 233,210

하지만이 코드는 나에게 다음과 같은 오류 제공 : 나는 단지 하나의 그래프에 2 개 상자 그림이있을 수 있기 때문에 그것의 생각

--------------------------------------------------------------------------- 
ValueError        Traceback (most recent call last) 
<ipython-input-275-9c68ce91596f> in <module>() 
     1 fig = plt.figure() 
     2 for i in range(0,25): 
----> 3  ax = plt.subplot(1,2,i+1) 
     4  toPlot1.boxplot(column='Score',by=toPlot1.columns[i+1],ax=ax) 
     5 fig.suptitle('test title', fontsize=20) 

E:\Anaconda2\lib\site-packages\matplotlib\pyplot.pyc in subplot(*args, **kwargs) 
    1020 
    1021  fig = gcf() 
-> 1022  a = fig.add_subplot(*args, **kwargs) 
    1023  bbox = a.bbox 
    1024  byebye = [] 

E:\Anaconda2\lib\site-packages\matplotlib\figure.pyc in add_subplot(self, *args, **kwargs) 
    1003      self._axstack.remove(ax) 
    1004 
-> 1005    a = subplot_class_factory(projection_class)(self, *args, **kwargs) 
    1006 
    1007   self._axstack.add(key, a) 

E:\Anaconda2\lib\site-packages\matplotlib\axes\_subplots.pyc in __init__(self, fig, *args, **kwargs) 
    62      raise ValueError(
    63       "num must be 1 <= num <= {maxn}, not {num}".format(
---> 64        maxn=rows*cols, num=num)) 
    65     self._subplotspec = GridSpec(rows, cols)[int(num) - 1] 
    66     # num - 1 for converting from MATLAB to python indexing 

ValueError: num must be 1 <= num <= 2, not 3 

를?

이 문제를 해결하는 방법에 대한 아이디어가 있으십니까? 모든 포인터는 매우 높이 평가 될 것입니다.

TIA. 당신은 단지 두 개의 줄거리를 생성

답변

10

참고 :

ax = plt.subplot(1,2,i+1) 

첫 번째 인수는 각 행의 플롯의 수와 컬럼 당 플롯의 초 수입니다 (또한 the matplotlib.pyplot.subplot documentation 참조). 귀하의 경우에 가능한 플롯 수는 1*2 = 2입니다. 당신은 예를 들어, 사용하면 수 (25)를 만들려면 :

ax = plt.subplot(5,5,i+1) 

5 행 당 플롯과 5 열마다 너무 많은 5*5 = 25

+2

감사의 총 수를 추가 할 수 있습니다. 그건 내 바보 같았 어. 참고 사항 : 인터넷에서 사용할 수있는 코드를 복사하여 붙여 넣기 전에 매개 변수를 올바르게 이해합니다. – Patthebug