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
)