2017-09-22 1 views
1

matplotlib에 여러 개의 서브 플로트를 플롯하려는 경우 각 서브 플로트에는 인셋 축이 있어야합니다. 삽입 축이 mpl_toolkits.axes_grid.inset_locator.inset_axes()을 사용하여 추가 된 단일 축에서 작동하도록 코드 예제를 얻을 수 있으며 인셋 축없이 서브 플로트를 정밀하게 플로팅 할 수 있지만 루프의 서브 플로트에서 동일한 작업을 수행 할 때 TypeError: 'AxesHostAxes' object is not callable이 두번째 subplot. 이것은 number_of_plots이 == 1 일 때> 1 일 때 작동해야한다는 것이 이상하게 보입니다. 어떻게해야합니까, 아니면 버그입니까? 그것은 버그가 아니라matplotlib을 사용하여 subplot에 inset_axes를 추가하는 방법

from matplotlib import pyplot as plt 
from mpl_toolkits.axes_grid.inset_locator import inset_axes 
import numpy as np 
x = np.linspace(0, 2 * np.pi, 100) 
y = np.sin(x) 
n_row, n_col = 4, 4 
fig = plt.figure(1,(10,10)) 
#number_of_plots = 1 Works! 
number_of_plots = n_row * n_col # Does not work! 
for idx in range(number_of_plots): 
    ax = fig.add_subplot(n_row, n_col, idx + 1) 
    ax.plot(x, y) 
    inset_axes = inset_axes(ax, 
          width="30%", # width = 30% of parent_bbox 
          height="30%", # height : 1 inch 
          ) 

Error in inset_axes

답변

2

(matplotlib.__version__는 '1.5.1'이다). inset_axes을 다시 정의하고 있습니다.

라인 앞에 inset_axes = inset_axes(...), inset_axesmpl_toolkits.axes_grid.inset_locator의 함수입니다. 그 후에는 inset_axes이 그 함수의 리턴 값이되며 AxesHostAxes입니다.

물론 일반적인 조언은 다음과 같습니다. 코드에서 가져 오거나 사용하는 함수와 같은 이름으로 변수를 호출하지 마십시오.

구체적인 해결책 :

ax_ins = inset_axes(ax, width="30%", height="30%") 
관련 문제