diff --git a/examples.py b/examples.py index 94ec0ef..629d994 100755 --- a/examples.py +++ b/examples.py @@ -83,7 +83,7 @@ def short_demo(): axs.plot(x, np.cos(x)) axs.plot(x, np.sin(x)) fig.clear() - axs = fig.add_subplot(1, 1, 0) + axs = fig.add_subplot(1, 1, 1) axs.plot(x, np.sin(x)+1) axs.plot(x, np.cos(x)-1) axs.text(0, 0, 'figure cleared then re-used') diff --git a/pyqtmpl/figure.py b/pyqtmpl/figure.py index 5712f34..e6a5705 100644 --- a/pyqtmpl/figure.py +++ b/pyqtmpl/figure.py @@ -124,10 +124,10 @@ def add_subplot(self, nrows, ncols, index, projection=None, polar=None, **kwargs raise NotImplementedError('projection keyword in add_subplot is not ready') if polar is not None and polar is not False: raise NotImplementedError('polar projection is not ready') - row = int(np.floor(index/ncols)) + row = int(np.floor((index-1)/ncols)) if row > (nrows-1): raise ValueError('index {} would be on row {}, but the last row is {}!'.format(index, row, nrows-1)) - col = index % ncols + col = (index-1) % ncols ax = Axes(**kwargs) self.layout.addItem(ax, row, col) if self.axes is None: diff --git a/pyqtmpl/pyplot.py b/pyqtmpl/pyplot.py index c1f176f..d2b2574 100644 --- a/pyqtmpl/pyplot.py +++ b/pyqtmpl/pyplot.py @@ -78,7 +78,7 @@ def pick_share(share, ii, jj, axs_): subplot_kw = subplot_kw if subplot_kw is not None else {} for i in range(nrows): for j in range(ncols): - index = i*ncols + j + index = i*ncols + j + 1 axs[i, j] = fig.add_subplot( nrows, ncols, index, sharex=pick_share(sharex, i, j, axs), sharey=pick_share(sharey, i, j, axs),