1# SPDX-License-Identifier: GPL-2.0 2# 3# Copyright (C) 2019, VMware Inc, Tzvetomir Stoyanov <[email protected]> 4# Copyright (C) 2019, VMware Inc, Yordan Karadzhov <[email protected]> 5 6 7import matplotlib.pyplot as plt 8import matplotlib.lines as mlines 9import numpy as np 10import sys 11 12def newline(p1, p2): 13 ax = plt.gca() 14 xmin, xmax = ax.get_xbound() 15 16 if(p2[0] == p1[0]): 17 xmin = xmax = p1[0] 18 ymin, ymax = ax.get_ybound() 19 else: 20 ymax = p1[1]+(p2[1]-p1[1])/(p2[0]-p1[0])*(xmax-p1[0]) 21 ymin = p1[1]+(p2[1]-p1[1])/(p2[0]-p1[0])*(xmin-p1[0]) 22 23 l = mlines.Line2D([xmin,xmax], [ymin,ymax], color='red') 24 ax.add_line(l) 25 return l 26 27 28data = np.loadtxt(fname = sys.argv[1]) 29selected_ts = data[-1, 1] 30selected_ofs = data[-1, 0] 31data = data[:-1,:] 32 33x = data[:, 1] - data[:, 0] 34 35mean = x.mean() 36std = x.std() 37 38num_bins = 500 39min = x.min() #+ .4 * (x.max() - x.min()) 40max = x.max() #- .4 * (x.max() - x.min()) 41bins = np.linspace(min, max, num_bins, endpoint = False, dtype=int) 42 43fig, ax = plt.subplots() 44 45# the histogram of the data 46n, bins, patches = ax.hist(x, bins, histtype=u'step'); 47 48ax.set_xlabel('clock offset [$\mu$s]') 49ax.set_ylabel('entries') 50ax.set_title("$\sigma$=%i" % std) 51 52x1, y1 = [selected_ofs, min], [selected_ofs, max] 53newline(x1, y1) 54 55# Tweak spacing to prevent clipping of ylabel 56fig.tight_layout() 57plt.show() 58