def draw_error_vs_validation(error_vals, validation_vals, colors=("r", "b")): fig = tfmpl.create_figure(figsize=(4, 4)) ax = fig.add_subplot(111) ax.plot(*zip(*error_vals), c=colors[0]) ax.plot(*zip(*validation_vals), c=colors[1]) return fig
def init_fig(*args, **kwargs): '''Initialize figures.''' fig = tfmpl.create_figure(figsize=(8, 6)) ax = fig.add_subplot(111, projection='3d', elev=50, azim=-30) ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 1.0)) ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 1.0)) ax.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 1.0)) ax.set_title('Gradient descent on Beale surface') ax.set_xlabel('$x$') ax.set_ylabel('$y$') ax.set_zlabel('beale($x$,$y$)') xx, yy = np.meshgrid(np.linspace(-4.5, 4.5, 40), np.linspace(-4.5, 4.5, 40)) zz = beale(xx, yy) ax.plot_surface(xx, yy, zz, norm=LogNorm(), rstride=1, cstride=1, edgecolor='none', alpha=.8, cmap=cm.jet) ax.plot([3], [.5], [beale(3, .5)], 'k*', markersize=5) for o in optimizers: path, = ax.plot([], [], [], label=o[1]) paths.append(path) ax.legend(loc='upper left') fig.tight_layout() return fig, paths
def draw_scatter(vals, color): fig = tfmpl.create_figure(figsize=(4, 4)) ax = fig.add_subplot(111) ax.scatter(*zip(*vals), c=color) fig.tight_layout() return fig
def draw(a, b, c, d=None, e=None): debug['a'] = a debug['b'] = b debug['c'] = c debug['d'] = d debug['e'] = e return tfmpl.create_figure()
def init(t): nonlocal rect fig = tfmpl.create_figure(figsize=(4, 4), dpi=100) ax = fig.add_axes([0, 0, 1, 1]) ax.invert_yaxis() rect = ax.add_patch( patches.Rectangle((0, 0), 0.1, 0.1, facecolor=(0, 1, 0))) return fig, rect
def draw_hinton_plot(matrices, trans=True, max_val=None, max_weight=None, scale=True, colors=("red", "blue"), titles=(), step=0): headline = "Hinton plot, step %d" % step if len(titles) == 0: titles = ["Plot %d" % i for i in range(len(matrices))] fig = tfmpl.create_figure() fig.suptitle(headline, fontsize=18) axes = fig.subplots(1, len(matrices)) for matrix, title, ax in zip(matrices, titles, axes): ax.clear() if trans: matrix = matrix.transpose() if max_val is None: # maxval max_val = np.abs(matrix).max() if max_weight is None: # maxsize max_weight = 2**np.ceil(np.log(max_val) / np.log(2)) ax.set_title(title) ax.patch.set_facecolor('gray') ax.set_aspect('auto', 'box') ax.xaxis.set_major_locator(plt.NullLocator()) ax.yaxis.set_major_locator(plt.NullLocator()) y_max = (matrix.shape[1] - 1) * max_weight for (x, y), w in np.ndenumerate(matrix): color = colors[0] if w > 0 else colors[1] if scale: size = max( 0.01, np.sqrt(min(max_weight, max_weight * np.abs(w) / max_val))) else: size = np.sqrt(min(np.abs(w), max_weight)) bottom_left = [x - size / 2, (y_max - y) - size / 2] rect = plt.Rectangle(bottom_left, size, size, facecolor=color, edgecolor=color) ax.add_patch(rect) ax.autoscale_view() ax.invert_yaxis() buf = io.BytesIO() fig.savefig(buf, format="png") buf.seek(0) return buf.getvalue()
def draw_scatter(self, data): '''Draw scatter plots. One for each color.''' fig = tfmpl.create_figure() # plt.imshow(data[:, :, 0]) # plt.show() ax = fig.add_subplot(111) ax.imshow(data[:, :, 0]) fig.tight_layout() return fig
def draw_matrix_tb(matrix, figsize=(4, 4)): """ Matrix plotting for tensorboard """ fig = tfmpl.create_figure(figsize=figsize) ax = fig.add_subplot(111) im = ax.pcolor(matrix) ax.invert_yaxis() fig.colorbar(im) fig.tight_layout() return fig
def draw_confusion_matrix(matrix, axis_labels, figsize): '''Draw confusion matrix for MNIST.''' fig = tfmpl.create_figure(figsize=figsize) ax = fig.add_subplot(111) ax.set_title('Confusion matrix') tfmpl.plots.confusion_matrix.draw(ax, matrix, axis_labels=axis_labels, normalize=True) return fig
def draw_confusion_matrix(matrix): '''Draw confusion matrix for MNIST.''' fig = tfmpl.create_figure(figsize=(7, 7)) ax = fig.add_subplot(111) ax.set_title('Confusion matrix for big5 classification') tfmpl.plots.confusion_matrix.draw(ax, matrix, axis_labels=['0', '1'], normalize=True) return fig
def draw_scatter_subplot(self, data1, data2): '''Draw scatter plots. One for each color.''' fig = tfmpl.create_figure() ax = fig.add_subplot(122) ax.imshow(data1[:, :, :]) ax = fig.add_subplot(121) try: ax.imshow(data2[:, :, :]) except: ax.imshow(data2[:, :, 0]) fig.tight_layout() return fig
def _create_tfmpl_figure(l, r, pair_label, left_label, right_label) -> Figure: fig: Figure = tfmpl.create_figure() a = fig.add_subplot(1, 2, 1) a.imshow(l) a.axis('off') b = fig.add_subplot(1, 2, 2) b.imshow(r) b.axis('off') fig.tight_layout() if str(pair_label) == '1': figure_title = "same ({}-{})".format(left_label, right_label) else: figure_title = "different ({}-{})".format(left_label, right_label) fig.suptitle(figure_title, fontsize=32) return fig
def draw_dendrogram(features, labels, metric='euclidean', mode='average', title='Dendrogram', orient='top', lrot=90.0): fig = tfmpl.create_figure(figsize=(6, 10)) ax = fig.add_subplot(111) print(features) cluster_history = sch.linkage(features, method=mode, metric=metric) sch.dendrogram(cluster_history, labels=labels, orientation=orient, leaf_rotation=lrot, ax=ax) plt.tight_layout() ax.set_title(title) ax.set_ylabel(metric + ' distance') buf = io.BytesIO() fig.savefig(buf, format="png") buf.seek(0) return buf.getvalue()
def draw(a): debug['called'] += 1 debug['a'].append(a) return tfmpl.create_figure()
def init(a, b, c, d=None, e=None): debug['init_args'] = [a, b, c, d, e] return tfmpl.create_figure(), None
def init(a): debug['init_called'] += 1 debug['a_init'] = a return tfmpl.create_figure(), None
def draw_tf_clusters_plot(feat, labels): fig: Figure = tfmpl.create_figure() return _draw_scatter(fig, feat, labels)