11#!/usr/bin/env python3
2+ """
3+ plot a single variable from an output file
4+
5+ Usage: ./plotvar.py filename variable
6+ """
27
38import argparse
49
813import pyro .util .io_pyro as io
914from pyro .mesh import patch
1015
11- # plot a single variable from an output file
12- #
13- # Usage: ./plotvar.py filename variable
14-
1516
1617def makeplot (plotfile , variable , outfile ,
17- width = 6.5 , height = 5.25 ,
18+ width = 6.5 , height = 5.25 , dpi = 100 , notitle = False ,
1819 log = False , compact = False , quiet = False ):
1920
2021 sim = io .read (plotfile )
22+ sim .cc_data .fill_BC_all ()
2123
2224 if isinstance (sim , patch .CellCenterData2d ):
2325 myd = sim
2426 else :
2527 myd = sim .cc_data
2628 myg = myd .grid
2729
28- plt .figure (num = 1 , figsize = (width , height ), dpi = 100 , facecolor = 'w' )
30+ fig = plt .figure (num = 1 , figsize = (width , height ), dpi = 100 , facecolor = 'w' )
31+ ax = fig .add_subplot (111 )
32+
33+ if variable == "vort" :
34+ vx = myd .get_var ("x-velocity" )
35+ vy = myd .get_var ("y-velocity" )
36+
37+ var = myg .scratch_array ()
2938
30- var = myd .get_var (variable )
39+ var [myg .ilo :myg .ihi + 1 , myg .jlo :myg .jhi + 1 ] = \
40+ 0.5 * (vy [myg .ilo + 1 :myg .ihi + 2 , myg .jlo :myg .jhi + 1 ] -
41+ vy [myg .ilo - 1 :myg .ihi , myg .jlo :myg .jhi + 1 ])/ myg .dx - \
42+ 0.5 * (vx [myg .ilo :myg .ihi + 1 , myg .jlo + 1 :myg .jhi + 2 ] -
43+ vx [myg .ilo :myg .ihi + 1 , myg .jlo - 1 :myg .jhi ])/ myg .dy
44+
45+ else :
46+ var = myd .get_var (variable )
3147
3248 if log :
3349 var = np .log10 (var )
3450
35- img = plt .imshow (np .transpose (var .v ()),
36- interpolation = "nearest" , origin = "lower" ,
37- extent = [myg .xmin , myg .xmax , myg .ymin , myg .ymax ])
51+ img = ax .imshow (np .transpose (var .v ()),
52+ interpolation = "nearest" , origin = "lower" ,
53+ extent = [myg .xmin , myg .xmax , myg .ymin , myg .ymax ])
3854
3955 if not compact :
40- plt .colorbar (img )
41-
42- plt .xlabel ("x" )
43- plt .ylabel ("y" )
56+ fig .colorbar (img )
57+ if not notitle :
58+ fig .suptitle (f"{ variable } " )
59+ ax .set_xlabel ("x" )
60+ ax .set_ylabel ("y" )
4461
4562 if compact :
46- plt .axis ("off" )
47- plt .subplots_adjust (bottom = 0.0 , top = 1.0 , left = 0.0 , right = 1.0 )
48- plt .savefig (outfile )
63+ ax .axis ("off" )
64+ fig .subplots_adjust (bottom = 0.0 , top = 1.0 , left = 0.0 , right = 1.0 )
65+ fig .savefig (outfile , bbox_inches = "tight" )
4966 else :
50- plt .savefig (outfile , bbox_inches = "tight" )
67+ fig .tight_layout ()
68+ fig .savefig (outfile , bbox_inches = "tight" , dpi = dpi )
5169
5270 if not quiet :
5371 plt .show ()
@@ -61,6 +79,8 @@ def get_args():
6179 metavar = "plot.png" , help = "output file name" )
6280 parser .add_argument ("--log" , action = "store_true" ,
6381 help = "plot log of variable" )
82+ parser .add_argument ("--notitle" , action = "store_true" ,
83+ help = "suppress the title at the top of the figure" )
6484 parser .add_argument ("--compact" , action = "store_true" ,
6585 help = "remove axes and border" )
6686 parser .add_argument ("--quiet" , action = "store_true" ,
@@ -69,6 +89,8 @@ def get_args():
6989 metavar = "width" , help = "plot width (inches)" )
7090 parser .add_argument ("-H" , type = float , default = 5.25 ,
7191 metavar = "height" , help = "plot height (inches)" )
92+ parser .add_argument ("--dpi" , type = int , default = 100 ,
93+ metavar = "dpi" , help = "dots per inch" )
7294 parser .add_argument ("plotfile" , type = str , nargs = 1 ,
7395 help = "the plotfile you wish to plot" )
7496 parser .add_argument ("variable" , type = str , nargs = 1 ,
@@ -82,5 +104,5 @@ def get_args():
82104 args = get_args ()
83105
84106 makeplot (args .plotfile [0 ], args .variable [0 ], args .o ,
85- width = args .W , height = args .H ,
107+ width = args .W , height = args .H , dpi = args . dpi , notitle = args . notitle ,
86108 log = args .log , compact = args .compact , quiet = args .quiet )
0 commit comments