matplotlibに複数のサブプロットをプロットしようとしていますが、各サブプロットにはインセット軸が必要です。私はコード軸をインセット軸がmpl_toolkits.axes_grid.inset_locator.inset_axes()
を使って追加された単軸で動作させることができますが、インセット軸なしでサブプロットを細かくプロットすることはできますが、ループ内でサブプロットを同じようにしようとするとTypeError: 'AxesHostAxes' object is not callable
第2サブプロット。これは、number_of_plots
が== 1で、> 1ではないときに動作するはずです。どうすればいいのですか、それともバグでしょうか?それはバグではありませんmatplotlibでサブプロットに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
)