Completely forgot matplotlib draws on top of pre existing data if using the same figure. The below code works to do what I want without needing to create my own colormap.
plt.clf()
# Mask array with mask pixels set to 1 and rest set to 0
mask = nib.load(os.path.join(mask_path, f))
# Grey scale MRI image slice
image = nib.load(os.path.join(images_path, f))
# Extracting pixel arrays
mask_data = mask.get_fdata()
image_data = image.get_fdata()
# Transposing and flipping to fix visual orientation
image_data = image_data.transpose((1,0))
image_data = np.flip(image_data,axis=0)
mask_data = mask_data.transpose((1,0))
mask_data = np.flip(mask_data,axis=0)
mask_data[mask_data==0] = None
plt.imshow(image_data,cmap='gray')
plt.imshow(mask_data,cmap = 'autumn')
Result:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…