def draw_image(img, label=None, dpi=72, facecolor='white', cmap=cm.gray, output_filename=None, **extra): #@UndefinedVariable ''' ''' img = img.copy() pylab.clf() fig = pylab.figure(0, dpi=dpi, facecolor=facecolor, figsize=(img.shape[0]/dpi, img.shape[1]/dpi))#, tight_layout=True fig.frameon=False #pylab.subplots_adjust(wspace=0, hspace=0, left=0, right=1, bottom=0, top=1) if img.min() != img.max(): img -= img.min() img /= img.max() #fig.set_size_inches(10, 10) #ax = pylab.Axes(fig, [0., 0., 10., 10.]) #ax.set_axis_off() #fig.add_axes(ax) ax = fig.add_axes((0,0,1,1), frameon=False) #ax = pylab.axes(frameon=False) ax.set_axis_off() ax.imshow(img, cmap=cmap)#, aspect = 'normal') if label is not None: ax.text(10, 20, label, color='black', backgroundcolor='white', fontsize=8) if output_filename is not None: fig.savefig(format_utility.new_filename(output_filename, ext='png'), dpi=dpi) return fig, ax
def plot_scatter(output, x, x_label, y, y_label, color=None, dpi=72): ''' Plot a scatter plot ''' if pylab is None: return fig = pylab.figure(dpi=dpi) ax = fig.add_subplot(111) if color is not None: sc = ax.scatter(x, y, cmap=cm.cool, c=color) #@UndefinedVariable v1 = min(numpy.min(x), numpy.min(y)) v2 = max(numpy.max(x), numpy.max(y)) ax.plot(numpy.asarray([v1, v2]), numpy.asarray([v1, v2])) pylab.colorbar(sc) else: ax.scatter(x, y) pylab.xlabel(x_label) pylab.ylabel(y_label) fig.savefig(format_utility.new_filename( output, x_label.lower().replace(' ', '_') + "_" + y_label.lower().replace(' ', '_') + "_summary_", ext="png"), dpi=dpi)
def plot_lines(output, lines, labels, ylabel=None, xlabel=None, dpi=72, prefix=None): ''' ''' fig = pylab.figure(dpi=dpi) ax = fig.add_subplot(111) cmap = cm.jet #@UndefinedVariable markers = ['s', 'o', '^', '>', 'v', 'd', 'p', 'h', '8', '+', 'x'] for i in xrange(len(lines)): ax.plot(lines[i], markers[i], c=cmap(float(i + 1) / len(lines)), label=labels[i]) if ylabel is not None: pylab.ylabel(ylabel) if xlabel is not None: pylab.xlabel(xlabel) lgd = ax.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0., prop={'size': 8}) fig.savefig(format_utility.new_filename(output, ext="png", prefix=prefix), dpi=dpi, bbox_extra_artists=(lgd, ), bbox_inches='tight')
def plot_line(output, x, y, x_label=None, y_label=None, color=None, marker_idx=None, dpi=72): ''' Plot a scatter plot ''' if pylab is None: return fig = pylab.figure(dpi=dpi) ax = fig.add_subplot(111) if x is None: x = numpy.arange(len(y)) x = numpy.asarray(x) y = numpy.asarray(y) ax.plot(x, y) if marker_idx is not None: ax.plot(x[marker_idx], y[marker_idx], linestyle='None', marker='+', color='r') ax.invert_xaxis() if x_label is not None: pylab.xlabel(x_label) if y_label is not None: pylab.ylabel(y_label) prefix = "" if x_label is not None: prefix += x_label.lower().replace(' ', '_')+"_" if y_label is not None: prefix += y_label.lower().replace(' ', '_')+"_" fig.savefig(format_utility.new_filename(output, prefix+"summary_", ext="png"), dpi=dpi)
def plot_histogram_cum(output, vals, x_label, y_label, th=None, dpi=72): ''' Plot a histogram of the distribution ''' if pylab is None: return fig = pylab.figure(dpi=dpi) ax = fig.add_subplot(111) vals = ax.hist(-vals, bins=numpy.sqrt(len(vals)), cumulative=True) if th is not None: h = pylab.gca().get_ylim()[1] pylab.plot((th, th), (0, h)) pylab.xlabel(x_label) pylab.ylabel('Cumulative '+y_label) fig.savefig(format_utility.new_filename(output, x_label.lower().replace(' ', '_')+"_"+y_label.lower().replace(' ', '_')+"_summary_", ext="png"), dpi=dpi)
def plot_lines(output, lines, labels, ylabel=None, xlabel=None, dpi=72, prefix=None): ''' ''' fig = pylab.figure(dpi=dpi) ax = fig.add_subplot(111) cmap = cm.jet#@UndefinedVariable markers = ['s', 'o', '^', '>', 'v', 'd', 'p', 'h', '8', '+', 'x'] for i in xrange(len(lines)): ax.plot(lines[i], markers[i], c=cmap(float(i+1)/len(lines)), label=labels[i]) if ylabel is not None: pylab.ylabel(ylabel) if xlabel is not None: pylab.xlabel(xlabel) lgd=ax.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0., prop={'size':8}) fig.savefig(format_utility.new_filename(output, ext="png", prefix=prefix), dpi=dpi, bbox_extra_artists=(lgd,), bbox_inches='tight')
def plot_embedding(x, y, selected=None, group=None, dpi=80, **extra): ''' Plot an embedding :Parameters: x : array X coordindates y : array Y coordindates selected : array, optional Plot selected points dpi : int Figure resolution extra : dict Unused key word arguments :Returns: fig : Figure Matplotlib figure ax : Axes Matplotlib axes ''' fig = pylab.figure(dpi=dpi) ax = fig.add_subplot(111) if group is not None: refs = numpy.unique(group) beg, inc = 0.0, 1.0 / len(refs) for r in refs: sel = r == group color = cm.spectral(beg) #@UndefinedVariable ax.plot(x[sel], y[sel], 'o', ls='.', markersize=3, c=color, **extra) beg += inc else: ax.plot(x, y, 'ro', ls='.', markersize=3, **extra) if selected is not None: ax.plot(x[selected], y[selected], 'k+', ls='.', markersize=2, **extra) return fig, ax
def draw_image(img, label=None, dpi=72, facecolor='white', cmap=cm.gray, output_filename=None, **extra): #@UndefinedVariable ''' ''' img = img.copy() pylab.clf() fig = pylab.figure(0, dpi=dpi, facecolor=facecolor, figsize=(img.shape[0] / dpi, img.shape[1] / dpi)) #, tight_layout=True fig.frameon = False #pylab.subplots_adjust(wspace=0, hspace=0, left=0, right=1, bottom=0, top=1) if img.min() != img.max(): img -= img.min() img /= img.max() #fig.set_size_inches(10, 10) #ax = pylab.Axes(fig, [0., 0., 10., 10.]) #ax.set_axis_off() #fig.add_axes(ax) ax = fig.add_axes((0, 0, 1, 1), frameon=False) #ax = pylab.axes(frameon=False) ax.set_axis_off() ax.imshow(img, cmap=cmap) #, aspect = 'normal') if label is not None: ax.text(10, 20, label, color='black', backgroundcolor='white', fontsize=8) if output_filename is not None: fig.savefig(format_utility.new_filename(output_filename, ext='png'), dpi=dpi) return fig, ax
def plot_scatter(output, x, x_label, y, y_label, color=None, dpi=72): ''' Plot a scatter plot ''' if pylab is None: return fig = pylab.figure(dpi=dpi) ax = fig.add_subplot(111) if color is not None: sc = ax.scatter(x, y, cmap=cm.cool, c=color)#@UndefinedVariable v1 = min(numpy.min(x),numpy.min(y)) v2 = max(numpy.max(x),numpy.max(y)) ax.plot(numpy.asarray([v1, v2]), numpy.asarray([v1, v2])) pylab.colorbar(sc) else: ax.scatter(x, y) pylab.xlabel(x_label) pylab.ylabel(y_label) fig.savefig(format_utility.new_filename(output, x_label.lower().replace(' ', '_')+"_"+y_label.lower().replace(' ', '_')+"_summary_", ext="png"), dpi=dpi)
def plot_histogram_cum(output, vals, x_label, y_label, th=None, dpi=72): ''' Plot a histogram of the distribution ''' if pylab is None: return fig = pylab.figure(dpi=dpi) ax = fig.add_subplot(111) vals = ax.hist(-vals, bins=numpy.sqrt(len(vals)), cumulative=True) if th is not None: h = pylab.gca().get_ylim()[1] pylab.plot((th, th), (0, h)) pylab.xlabel(x_label) pylab.ylabel('Cumulative ' + y_label) fig.savefig(format_utility.new_filename( output, x_label.lower().replace(' ', '_') + "_" + y_label.lower().replace(' ', '_') + "_summary_", ext="png"), dpi=dpi)
def plot_line(output, x, y, x_label=None, y_label=None, color=None, marker_idx=None, dpi=72): ''' Plot a scatter plot ''' if pylab is None: return fig = pylab.figure(dpi=dpi) ax = fig.add_subplot(111) if x is None: x = numpy.arange(len(y)) x = numpy.asarray(x) y = numpy.asarray(y) ax.plot(x, y) if marker_idx is not None: ax.plot(x[marker_idx], y[marker_idx], linestyle='None', marker='+', color='r') ax.invert_xaxis() if x_label is not None: pylab.xlabel(x_label) if y_label is not None: pylab.ylabel(y_label) prefix = "" if x_label is not None: prefix += x_label.lower().replace(' ', '_') + "_" if y_label is not None: prefix += y_label.lower().replace(' ', '_') + "_" fig.savefig(format_utility.new_filename(output, prefix + "summary_", ext="png"), dpi=dpi)
def plot_embedding(x, y, selected=None, group=None, dpi=80, **extra): ''' Plot an embedding :Parameters: x : array X coordindates y : array Y coordindates selected : array, optional Plot selected points dpi : int Figure resolution extra : dict Unused key word arguments :Returns: fig : Figure Matplotlib figure ax : Axes Matplotlib axes ''' fig = pylab.figure(dpi=dpi) ax = fig.add_subplot(111) if group is not None: refs = numpy.unique(group) beg, inc = 0.0, 1.0/len(refs) for r in refs: sel = r == group color = cm.spectral(beg)#@UndefinedVariable ax.plot(x[sel], y[sel], 'o', ls='.', markersize=3, c=color, **extra) beg += inc else: ax.plot(x, y, 'ro', ls='.', markersize=3, **extra) if selected is not None: ax.plot(x[selected], y[selected], 'k+', ls='.', markersize=2, **extra) return fig, ax