2017-09-22 7 views
1

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 
          ) 

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%") 
関連する問題