def plot_channel(image, name, cmap='gist_heat', log=True, dex=3, zero_factor=1.0e-10,
label=None, label_color='w', label_size='large'):
"""
This function will plot a single channel. *image* is an array shaped like
(N,M), *name* is the pefix for the output filename. *cmap* is the name of
the colormap to apply, *log* is whether or not the channel should be
logged. Additionally, you may optionally specify the minimum-value cutoff
for scaling as *dex*, which is taken with respect to the minimum value of
the image. *zero_factor* applies a minimum value to all zero-valued
elements. Optionally, *label*, *label_color* and *label_size* may be
specified.
"""
import matplotlib
import pylab
Nvec = image.shape[0]
image[np.isnan(image)] = 0.0
ma = image[image>0.0].max()
image[image==0.0] = ma*zero_factor
if log:
mynorm = matplotlib.colors.LogNorm(ma/(10.**dex), ma)
pylab.clf()
pylab.gcf().set_dpi(100)
pylab.gcf().set_size_inches((Nvec/100.0, Nvec/100.0))
pylab.gcf().subplots_adjust(left=0.0, right=1.0, bottom=0.0, top=1.0, wspace=0.0, hspace=0.0)
mycm = pylab.cm.get_cmap(cmap)
if log:
pylab.imshow(image,cmap=mycm, norm=mynorm, interpolation='nearest')
else:
pylab.imshow(image,cmap=mycm, interpolation='nearest')
if label is not None:
pylab.text(20, 20,label, color = label_color, size=label_size)
pylab.savefig("%s_%s.png" % (name,cmap))
pylab.clf()
评论列表
文章目录