From 3bafd254c8ed2aa44bcb17e1fd306a5ece149286 Mon Sep 17 00:00:00 2001 From: ZHUO Xu <136371391@qq.com> Date: Sun, 14 Jan 2024 15:16:28 +0800 Subject: [PATCH] Update plot.py --- crip/plot.py | 84 ++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/crip/plot.py b/crip/plot.py index 71dfcf7..5b3943c 100644 --- a/crip/plot.py +++ b/crip/plot.py @@ -131,12 +131,12 @@ def makeImageGrid(subimages: List[TwoD], 'vmin0vmax1=False is not recommended because it might cause incorrect windowing. Make sure you know what you are doing.' ) - cripAssert(len(subimages) == ncols * nrows) - cripAssert(crops is None or len(crops) == nrows) - ncols = len(colTitles) nrows = len(rowTitles) + cripAssert(len(subimages) == ncols * nrows, 'Number of subimages should be equal to ncols * nrows.') + cripAssert(crops is None or len(crops) == nrows, 'Number of crops should be equal to nrows.') + if isinstance(cropLocs, str): cropLocs = [cropLocs] * nrows @@ -164,47 +164,47 @@ def makeImageGrid(subimages: List[TwoD], ax.get_xaxis().set_ticks([]) list(map(lambda x: x.set_visible(False), ax.spines.values())) - if i % ncols == 0: + if len(rects) != 0 and i % ncols == 0: ax.add_patch(rects[i // ncols]) - patch = zoomIn(im, *crops[i // ncols]) - patch = resize(patch, (cropSize, cropSize)) - cropLocs = cropLocs[i // ncols] - - if cropLocs == 'bottom right': - im[-patch.shape[0]:, -patch.shape[1]:] = patch - patchRect = matplotlib.patches.Rectangle((im.shape[1] - patch.shape[1], im.shape[0] - patch.shape[0]), - patch.shape[1], - patch.shape[0], - linewidth=1, - edgecolor=cropEdgeColor, - facecolor='none') - elif cropLocs == 'top left': - im[:patch.shape[0], :patch.shape[1]] = patch - patchRect = matplotlib.patches.Rectangle((0, 0), - patch.shape[1], - patch.shape[0], - linewidth=1, - edgecolor=cropEdgeColor, - facecolor='none') - elif cropLocs == 'bottom left': - im[-patch.shape[0]:, :patch.shape[1]] = patch - patchRect = matplotlib.patches.Rectangle((0, im.shape[0] - patch.shape[0]), - patch.shape[1], - patch.shape[0], - linewidth=1, - edgecolor=cropEdgeColor, - facecolor='none') - elif cropLocs == 'top right': - im[:patch.shape[0], -patch.shape[1]:] = patch - patchRect = matplotlib.patches.Rectangle((im.shape[1] - patch.shape[1], 0), - patch.shape[1], - patch.shape[0], - linewidth=1, - edgecolor=cropEdgeColor, - facecolor='none') - - ax.add_patch(patchRect) + patch = zoomIn(im, *crops[i // ncols]) + patch = resize(patch, (cropSize, cropSize)) + cropLocs = cropLocs[i // ncols] + + if cropLocs == 'bottom right': + im[-patch.shape[0]:, -patch.shape[1]:] = patch + patchRect = matplotlib.patches.Rectangle((im.shape[1] - patch.shape[1], im.shape[0] - patch.shape[0]), + patch.shape[1], + patch.shape[0], + linewidth=1, + edgecolor=cropEdgeColor, + facecolor='none') + elif cropLocs == 'top left': + im[:patch.shape[0], :patch.shape[1]] = patch + patchRect = matplotlib.patches.Rectangle((0, 0), + patch.shape[1], + patch.shape[0], + linewidth=1, + edgecolor=cropEdgeColor, + facecolor='none') + elif cropLocs == 'bottom left': + im[-patch.shape[0]:, :patch.shape[1]] = patch + patchRect = matplotlib.patches.Rectangle((0, im.shape[0] - patch.shape[0]), + patch.shape[1], + patch.shape[0], + linewidth=1, + edgecolor=cropEdgeColor, + facecolor='none') + elif cropLocs == 'top right': + im[:patch.shape[0], -patch.shape[1]:] = patch + patchRect = matplotlib.patches.Rectangle((im.shape[1] - patch.shape[1], 0), + patch.shape[1], + patch.shape[0], + linewidth=1, + edgecolor=cropEdgeColor, + facecolor='none') + + ax.add_patch(patchRect) if i < len(colTitles): ax.set_title(colTitles[i], loc='center', fontdict=fontdict)