def plot_box(box, title=None, path=None, format=None, scale="log", interval="pts", cmap="viridis"):
"""
This function ...
:param box:
:param title:
:param path:
:param format:
:param scale:
:param interval:
:param cmap:
:return:
"""
# Other new colormaps: plasma, magma, inferno
# Normalization
if scale == "log": norm = ImageNormalize(stretch=LogStretch())
elif scale == "sqrt": norm = ImageNormalize(stretch=SqrtStretch())
#elif scale == "skimage": norm = exposure.equalize_hist
else: raise ValueError("Invalid option for 'scale'")
if interval == "zscale":
vmin, vmax = ZScaleInterval().get_limits(box)
elif interval == "pts":
# Determine the maximum value in the box and the mimimum value for plotting
vmin = max(np.nanmin(box), 0.)
vmax = 0.5 * (np.nanmax(box) + vmin)
elif isinstance(interval, tuple):
vmin = interval[0]
vmax = interval[1]
else: raise ValueError("Invalid option for 'interval'")
#if scale == "skimage":
# vmin = 0.0
# vmax = 1.0
# Make the plot
plt.figure(figsize=(7,7))
plt.imshow(box, origin="lower", interpolation="nearest", vmin=vmin, vmax=vmax, norm=norm, cmap=cmap)
plt.xlim(0, box.shape[1]-1)
plt.ylim(0, box.shape[0]-1)
if title is not None: plt.title(title)
if path is None: plt.show()
else: plt.savefig(path, format=format)
plt.close()
# -----------------------------------------------------------------
评论列表
文章目录