Skip to content

Commit

Permalink
Update plot.py
Browse files Browse the repository at this point in the history
  • Loading branch information
z0gSh1u authored Jan 14, 2024
1 parent a1f03b1 commit 3bafd25
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions crip/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3bafd25

Please sign in to comment.