-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathplotvar.py
More file actions
executable file
·86 lines (62 loc) · 2.38 KB
/
Copy pathplotvar.py
File metadata and controls
executable file
·86 lines (62 loc) · 2.38 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
import argparse
from util import io
import mesh.patch as patch
# plot a single variable from an output file
#
# Usage: ./plotvar.py filename variable
def makeplot(plotfile, variable, outfile,
width=6.5, height=5.25,
log=False, compact=False, quiet=False):
sim = io.read(plotfile)
if isinstance(sim, patch.CellCenterData2d):
myd = sim
else:
myd = sim.cc_data
myg = myd.grid
plt.figure(num=1, figsize=(width, height), dpi=100, facecolor='w')
var = myd.get_var(variable)
if log:
var = np.log10(var)
plt.imshow(np.transpose(var.v()),
interpolation="nearest", origin="lower",
extent=[myg.xmin, myg.xmax, myg.ymin, myg.ymax])
if not compact:
plt.colorbar()
plt.xlabel("x")
plt.ylabel("y")
if compact:
plt.axis("off")
plt.subplots_adjust(bottom=0.0, top=1.0, left=0.0, right=1.0)
plt.savefig(outfile)
else:
plt.savefig(outfile, bbox_inches="tight")
if not quiet:
plt.show()
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument("-o", type=str, default="plot.png",
metavar="plot.png", help="output file name")
parser.add_argument("--log", action="store_true",
help="plot log of variable")
parser.add_argument("--compact", action="store_true",
help="remove axes and border")
parser.add_argument("--quiet", action="store_true",
help="don't show the figure")
parser.add_argument("-W", type=float, default=6.5,
metavar="width", help="plot width (inches)")
parser.add_argument("-H", type=float, default=5.25,
metavar="height", help="plot height (inches)")
parser.add_argument("plotfile", type=str, nargs=1,
help="the plotfile you wish to plot")
parser.add_argument("variable", type=str, nargs=1,
help="the name of the solver used to run the simulation")
args = parser.parse_args()
return args
if __name__ == "__main__":
args = get_args()
makeplot(args.plotfile[0], args.variable[0], args.o,
width=args.W, height=args.H,
log=args.log, compact=args.compact, quiet=args.quiet)