-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathdata_plot.py
More file actions
executable file
·28 lines (24 loc) · 852 Bytes
/
data_plot.py
File metadata and controls
executable file
·28 lines (24 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python
from argparse import ArgumentParser
import numpy as np
import scipy
import scipy.stats
import matplotlib.pyplot as plt
arg_parser = ArgumentParser(description='plot data')
arg_parser.add_argument('file', help='data file to plot')
arg_parser.add_argument('--out', help='output file')
options = arg_parser.parse_args()
data = np.genfromtxt(options.file, dtype=[np.float64, np.float64],
delimiter=',', names=True)
plt.plot(data['x'], data['y'], 'ro')
slope, intercept, r, _, _ = scipy.stats.linregress(data['x'], data['y'])
result_str = ('slope = {0:.3f}, ' +
'intercept = {1:.3f}, ' +
'(R = {0:.3e})').format(slope, intercept, r)
print(result_str)
fit = slope*data['x'] + intercept
plt.plot(data['x'], fit, 'b-')
if options.out:
plt.savefig(options.out)
else:
plt.show()