def outlier_frequency_plot(path, angles, threshold): f, ax = base_plot() ax.plot(100 * np.cumsum(np.abs(angles) > threshold) / angles.size) ax.set_xlabel("Match number") ax.set_ylabel("Outlier fraction (%)") ax.set_ylim([0, 100]) f.savefig(path, bbox_inches='tight') plt.close(f)
def plot_covariance_matrix(S, labels): "Plot a covariance matrix with Hinton-ish diagram" covariance_matrix_font_size = 18 f, ax = base_plot(figsize=(4,4)) ax.invert_yaxis() # ax.imshow(S, interpolation="nearest", cmap="gray") n = S.shape[0] ax.spines["bottom"].set_visible(False) ax.spines["left"].set_visible(False) ax.get_xaxis().tick_top() ax.get_xaxis().set_ticks_position('none') ax.get_yaxis().set_ticks_position('none') ax.set_xticks(np.arange(n)) ax.set_yticks(np.arange(n)) ax.set_xticklabels(labels, fontsize=covariance_matrix_font_size) ax.set_yticklabels(labels, fontsize=covariance_matrix_font_size) def format_cov(c): if np.allclose(c, 0.0): return "0" elif np.allclose(c, 1.0): return "1" elif np.allclose(c, -1.0): return "-1" else: return "{0:0.2f}".format(c).replace("-0", "-").lstrip("0") def covcolor(c): return [1.0 - abs(c)]*3 def textcolor_for_cov(c): return "white" if abs(c) > 0.5 else "black" for x in range(n): for y in range(n): blob(ax, x, y, abs(S[x, y]), covcolor(S[x,y])) ax.text(x, y, format_cov(S[x, y]), fontsize=covariance_matrix_font_size, horizontalalignment="center", verticalalignment="center", color=textcolor_for_cov(S[x, y])) return f, ax
def plot_distribution(X): f, ax = base_plot(figsize=(8,4)) ax.hist(X, normed=True, bins=X.size/6) ax.set_ylabel("Frequency") return f, ax
def plot_scatter(X, Y): f, ax = base_plot(figsize=(8,4)) ax.plot(X, Y, '.') ax.set_xlabel("X") ax.set_ylabel("Y") return f, ax
#!/usr/bin/env python3 import sys import os import os.path import numpy as np import matplotlib.pyplot as plt from features_common import match_angle, base_plot if __name__ == "__main__": if len(sys.argv) >= 2: path = sys.argv[1] else: path = "." shape = np.loadtxt(os.path.join(path, "shape.txt")) matches = np.loadtxt(os.path.join(path, "matches.txt"), comments="#") angles = match_angle(matches, shape) f, ax = base_plot() ax.vlines(np.arange(angles.size), 0, angles) ax.set_ylim([-80, 80]) ax.set_xlabel("Feature number (by distance)") ax.set_ylabel("Angle") plt.show(f) plt.close(f)