forked from python-hydro/pyro2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotvar.py
More file actions
executable file
·71 lines (48 loc) · 1.56 KB
/
Copy pathplotvar.py
File metadata and controls
executable file
·71 lines (48 loc) · 1.56 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
import sys
import getopt
import mesh.patch as patch
# plot a single variable from an output file
#
# Usage: ./plotvar.py filename variable
def makeplot(myd, variable, outfile):
plt.figure(num=1, figsize=(6.5,5.25), dpi=100, facecolor='w')
var = myd.get_var(variable)
myg = myd.grid
img = plt.imshow(np.transpose(var.v()),
interpolation="nearest", origin="lower",
extent=[myg.xmin, myg.xmax, myg.ymin, myg.ymax])
plt.colorbar()
plt.xlabel("x")
plt.ylabel("y")
plt.savefig(outfile, bbox_inches="tight")
plt.show()
def usage():
usage="""
usage: plotvar.py [-h] [-o image.png] filename variable
positional arguments:
filename required inputs: filename to read from
variable required inputs: variable to plot from filename
optional arguments:
-h, --help show this help message and exit
-o image.png output image name. The extension .png will generate a PNG
file, .eps will generate an EPS file (default: plot.png).
"""
print usage
sys.exit()
if __name__== "__main__":
try: opts, next = getopt.getopt(sys.argv[1:], "o:h")
except getopt.GetoptError:
sys.exit("invalid calling sequence")
outfile = "plot.png"
for o, a in opts:
if o == "-h": usage()
if o == "-o": outfile = a
try: file = next[0]
except: usage()
try: variable = next[1]
except: usage()
myg, myd = patch.read(file)
makeplot(myd, variable, outfile)