@@ -835,6 +835,12 @@ QMCA examples:
835835 qmca -pa -q e -e 10 qmc.g*.s*.scalar.dat
836836 qmca -ta -q e -e 10 qmc.g*.s*.scalar.dat
837837
838+ saving plots to files (-i/--image uses prefix qmca_plot; --image-prefix sets a custom prefix)
839+ qmca -t -q e -i qmc.s*.scalar.dat
840+ qmca -ta -q ev --image-prefix myrun qmc.g*.s*.scalar.dat
841+ saving plots to PDF files (--image-format pdf for vector output suited to publication)
842+ qmca -t -q e --image-format pdf --image-prefix myrun qmc.s*.scalar.dat
843+
838844 multiple quantities and prefixes can be used for plots as well
839845'''
840846 self .log (examples )
@@ -931,9 +937,17 @@ QMCA examples:
931937 action = 'store_true' ,default = False ,
932938 help = 'Display output data sorted alphabetically by file name (default=%default).'
933939 )
934- parser .add_option ('-i' ,'--image' ,dest = 'image ' ,
940+ parser .add_option ('-i' ,'--image' , dest = 'save_image ' ,
935941 action = 'store_true' ,default = False ,
936- help = '(pending) Save image files (default=%default).'
942+ help = 'Save plot files (default prefix: qmca_plot).'
943+ )
944+ parser .add_option ('--image-prefix' ,dest = 'image_prefix' ,
945+ default = 'None' ,metavar = 'BASENAME' ,
946+ help = 'Save plot files with basename prefix (default=%default).'
947+ )
948+ parser .add_option ('--image-format' ,dest = 'image_format' ,
949+ default = 'png' ,metavar = 'FORMAT' ,
950+ help = 'Output format for saved plots: png, pdf, svg, or eps (default=%default).'
937951 )
938952 parser .add_option ('-r' ,'--report' ,dest = 'report' ,
939953 action = 'store_true' ,default = False ,
@@ -979,7 +993,7 @@ QMCA examples:
979993 help = 'Use twist weights in twist_info.dat files or not. Options: "use", "ignore", "require". "use" means use when present, "ignore" means do not use, "require" means must be used (default=%default).'
980994 )
981995
982- unsupported = set ('histogram image reblock report' .split ())
996+ unsupported = set ('histogram reblock report' .split ())
983997
984998 units = obj (hartree = 'Ha' ,ha = 'Ha' ,ev = 'eV' ,rydberg = 'Ry' ,ry = 'Ry' ,kelvin = 'K' ,kj_mol = 'kJ_mol' ,joules = 'J' )
985999
@@ -1064,9 +1078,19 @@ QMCA examples:
10641078 #end if
10651079 opt .join = j
10661080 #end if
1067- if opt .image == 'None' :
1068- opt .image = None
1081+ if opt .image_prefix != 'None' :
1082+ opt .image = opt .image_prefix
1083+ elif opt .save_image :
1084+ opt .image = 'qmca_plot'
1085+ else :
1086+ opt .image = None
1087+ #end if
1088+ image_formats = ('png' ,'pdf' ,'svg' ,'eps' )
1089+ fmt = opt .image_format .lower ().lstrip ('.' )
1090+ if fmt not in image_formats :
1091+ self .error ('image_format option is invalid\n image_format must be one of: {}\n you provided: {}' .format (image_formats ,opt .image_format ))
10691092 #end if
1093+ opt .image_format = fmt
10701094 twist_info_options = ('use' ,'ignore' ,'require' )
10711095 if opt .twist_info not in twist_info_options :
10721096 self .error ('twist_info option is invalid\n twist_info must be one of: {}\n you provided: {}' .format (twist_info_options ,opt .twist_info ))
@@ -1449,7 +1473,9 @@ QMCA examples:
14491473 tracestyle = color + line
14501474 histstyle = color + line
14511475 iplot ,itrace ,ihist = list (range (3 ))
1476+ mode_names = ['series' ,'trace' ,'histogram' ]
14521477 modes = [opt .plot ,opt .trace ,opt .histogram ]
1478+ save_plots = opt .image is not None
14531479 quantities = []
14541480 for q in opt .quantities :
14551481 all_present = True
@@ -1562,12 +1588,28 @@ QMCA examples:
15621588 ax .legend (loc = 2 ,bbox_to_anchor = (1.0 ,1.0 ),borderaxespad = 0. )
15631589 #end if
15641590 #end if
1591+ if save_plots :
1592+ safe_prefix = prefix .replace ('/' ,'_' ).replace (os .sep ,'_' )
1593+ fmt = opt .image_format
1594+ fname = '{0}_{1}_{2}_{3}.{4}' .format (
1595+ opt .image ,safe_prefix ,quantity ,mode_names [mode ],fmt )
1596+ save_kwargs = dict (format = fmt ,bbox_inches = 'tight' )
1597+ if fmt == 'png' :
1598+ save_kwargs ['dpi' ] = 150
1599+ #end if
1600+ fig .savefig (fname ,** save_kwargs )
1601+ if self .verbose :
1602+ self .log ('saved plot to {0}' .format (fname ),n = 1 )
1603+ #end if
1604+ plt .close (fig )
1605+ #end if
15651606 #end if
15661607 #end for
15671608 #end if
15681609 #end for
15691610 #end for
1570- plt .show ()
1611+ if not save_plots :
1612+ plt .show ()
15711613 #end if
15721614 #end def analyze_data
15731615#end class QMCA
0 commit comments