-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotmat.py
executable file
·46 lines (38 loc) · 1.2 KB
/
plotmat.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/env python3
import numpy as np
from matplotlib import rc
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
import sys
# plot matrix a
def matplot(a, titles=["", "", ""], fpath="", show=True):
rc('font', **{'family': 'serif', 'serif': ['Computer Modern']})
rc('text', usetex=True)
plt.rcParams.update({'font.size': 22})
f = plt.figure(figsize=(10, 10))
plt.matshow(a, f)
plt.title(titles[0])
plt.xlabel(titles[1])
plt.ylabel(titles[2])
plt.colorbar()
if len(fpath) > 0:
f.savefig(fpath, bbox_inches='tight') # save to file
if show:
plt.show()
plt.close()
show = False # show plots?
dfpath1 = "out.dat"
ndata = len(sys.argv) - 1
if len(sys.argv) > 1:
dfpath1 = sys.argv[1]
data1 = np.loadtxt(dfpath1)
if len(sys.argv) > 2:
dfpath2 = sys.argv[2]
data2 = np.loadtxt(dfpath2)
# plot matrix from file
if ndata > 1:
matplot(data1, ["Matrix 1", "$x$", "$y$"], fpath="matrix1.pdf")
matplot(data2, ["Matrix 2", "$x$", "$y$"], fpath="matrix2.pdf")
matplot(np.abs(data1-data2), ["Difference", "$x$", "$y$"], fpath="diff.pdf")
else:
matplot(data1, ["Matrix", "$x$", "$y$"], fpath="matrix.pdf")