Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from math import ceil
- import numpy as np
- import matplotlib as mlp
- import matplotlib.pyplot as plt
- mlp.rcParams['mathtext.fontset'] = 'stix'
- mlp.rcParams['font.family'] = 'STIXGeneral'
- mlp.pyplot.title(r'ABC123 vs $\mathrm{ABC123}^{123}$')
- mlp.rcParams['axes.labelsize'] = 15
- mlp.rcParams['axes.titlesize'] = 20
- mlp.rcParams['xtick.labelsize'] = 15
- mlp.rcParams['ytick.labelsize'] = 15
- def reject_outliers(data, m=2):
- return data[abs(data - np.mean(data)) < m * np.std(data)]
- def plotDistanceHistogram (distances_real, distances_false, name):
- distances_real = reject_outliers (distances_real, 3)
- distances_false = reject_outliers (distances_false, 3)
- weights_real = (np.ones_like (distances_real)) / len (distances_real)
- n, bins_n, patches_n = plt.hist (distances_real, 50, weights = weights_real, histtype = 'bar')
- weights_false = (np.ones_like (distances_false)) / len (distances_false)
- m, bins_m, patches_m = plt.hist (distances_false, 50, weights = weights_false, histtype = 'bar')
- plt.clf ()
- x = [bins_n[0]] + [0.5 * (bins_n[i] + bins_n[i + 1]) for i in xrange (len(bins_n) - 1)] + [bins_n[-1]]
- y = [0.0] + [patch.get_height () for patch in patches_n] + [0.0]
- plt.plot (x, y, color = 'green', alpha = 0.75, label = 'correspondencias reales', marker = 'o')
- plt.fill (x, y, color = 'green', alpha = 0.75)
- x = [bins_m[0]] + [0.5 * (bins_m[i] + bins_m[i + 1]) for i in xrange (len(bins_m) - 1)] + [bins_m[-1]]
- y = [0.0] + [patch.get_height () for patch in patches_m] + [0.0]
- plt.plot (x, y, color = 'red', alpha = 0.75, label = 'correspondencias falsas', marker = 'o')
- plt.fill (x, y, color = 'red', alpha = 0.75)
- plt.legend (bbox_to_anchor = (0., 1., 1., .12), loc = 'upper center', ncol = 2, mode = 'expand', fontsize = 15)
- plt.grid (True)
- plt.savefig ('histograma-distancias-' + name + '.png', bbox_inches = 'tight')
- def main ():
- mu, sigma = 0.25, 0.05
- x = mu + sigma * np.random.randn (10000)
- y = x + 0.2
- plotDistanceHistogram (x, y, 'prueba')
- if __name__ == "__main__":
- main ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement