parameters: (*args, **kwargs)
docstring: call signature::
  
        rootplot(file1, file2, file3, ..., **kwargs):
  
      build ROOT canvases from corresponding histograms in each of the *files*.
  
      call signature::
  
        rootplot(file, folder1, folder2, folder3, ..., **kwargs):
  
      build ROOT canvases from corresponding histograms in each of the *folders*
      in *file*.
  
      call signature::
  
        rootplot(file, target1, target2, target3, ..., **kwargs):
  
      build a ROOT canvas from each of the *targets* in *file*.
  
      With any of these call signatures, images are generated in an output
      directory along with a script with the necessary calls to :func:`plot`
      to reproduce each of the canvases.  The plot style is specified through
      *kwargs*, which can accept any of the options available to
      :mod:`rootplot` at the command-line.
docstring_summary: call signature::
docstring_tokens: call signature ::
function: def rootplot(*args, **kwargs):
      """
      call signature::
  
        rootplot(file1, file2, file3, ..., **kwargs):
  
      build ROOT canvases from corresponding histograms in each of the *files*.
  
      call signature::
  
        rootplot(file, folder1, folder2, folder3, ..., **kwargs):
  
      build ROOT canvases from corresponding histograms in each of the *folders*
      in *file*.
  
      call signature::
  
        rootplot(file, target1, target2, target3, ..., **kwargs):
  
      build a ROOT canvas from each of the *targets* in *file*.
  
      With any of these call signatures, images are generated in an output
      directory along with a script with the necessary calls to :func:`plot`
      to reproduce each of the canvases.  The plot style is specified through
      *kwargs*, which can accept any of the options available to
      :mod:`rootplot` at the command-line.
      """
      if 'config' in kwargs:
          write_config()
      options = fill_options(args, kwargs, scope='global')
      nfiles = len(options.filenames)
      ntargets = len(options.targets)
      if nfiles < 1:
          raise TypeError("%s takes at least 1 filename argument (0 given)" %
                          prog)
      elif ntargets > 0 and nfiles > 1:
          raise TypeError("%s cannot accept targets (%i given) when "
                          "multiple files are specified (%i given)" %
                          (prog, ntargets, nfiles))
      rootfiles = [RootFile(filename) for filename in options.filenames]
      #### Create the output directory structure
      if not options.noclean and os.path.exists(options.output):
          shutil.rmtree(options.output)
      for path, folders, objects in walk_rootfile('', rootfiles[0], options):
          if not os.path.exists(joined(options.output, path)):
              os.makedirs(joined(options.output, path))
      #### Loop over plots to make, building the necessary calls
      plotargs = get_plot_inputs(rootfiles, options)
      call_lists = []
      ndigits = int(math.log10(len(plotargs))) + 1
      for i, (filenames, targets) in enumerate(plotargs):
          argstring = ', '.join(["'%s'" % x for x in (filenames + targets +
                                                      options.configs)])
          reduced_kwargs = dict(kwargs)
          for key, value in reduced_kwargs.items():
              if key in global_opts:
                  del reduced_kwargs[key]
              elif isinstance(value, str):
                  reduced_kwargs[key] = "'%s'" % value
          if 'numbering' in kwargs:
              reduced_kwargs['numbering'] = i + 1
          optstring = ', '.join(['%s=%s' % (key, value)
                                 for key, value in reduced_kwargs.items()])
          if optstring:
              argstring = "%s, %s" % (argstring, optstring)
          plotpath, title, legentries = get_plotpath(filenames, targets)
          savepath = joined(options.output, plotpath)
          if 'numbering' in reduced_kwargs:
              dirs = savepath.split('/')
              dirs[-1] = str(i + 1).zfill(ndigits) + dirs[-1]
              savepath = '/'.join(dirs)
          call_vars = {'argstring' : argstring, 'ext' : options.ext,
                       'savepath' : savepath}
          if use_mpl:
              call_vars['trans'] = options.transparent
              call_vars['dpi'] = options.dpi
              api_call = ("figure, objects = "
                          "plotmpl(%(argstring)s)" % call_vars)
              save_call = ("figure.savefig('%(savepath)s', "
                           "transparent=%(trans)s, "
                           "dpi=%(dpi)s)" % call_vars)
          else:
              api_call = ("canvas, objects = "
                          "plot(%(argstring)s)" % call_vars)
              save_call = "canvas.SaveAs('%(savepath)s.%(ext)s')" % call_vars
          call_lists.append([api_call, save_call])
      #### Create scripts for that make the API calls
      ext = options.ext
      output = options.output
      processors = options.processors
      call_statements = '\n\n'.join([plotcall + '\n' + savecall 
                                     for plotcall, savecall in call_lists])
      allplots_script = allplots_template % locals()
      call_statements = "".join([multi_call_template % (plotcall, savecall) 
                                 for plotcall, savecall in call_lists])
      allplots_multi_script = allplots_multi_template % locals()
      write_to_file(allplots_script, joined(options.output, 'allplots.py'))
      write_to_file(allplots_multi_script, 
                   joined(options.output, 'allplots_multi.py'))
      #### Execute the calls
      if use_multiprocessing:
          original_dir = os.getcwd()
          os.chdir(options.output)
          exec(allplots_multi_script)
          os.chdir(original_dir)
      else:
          for i, call_list in enumerate(call_lists):
              make_calls(*call_list)
              report_progress(i + 1, len(plotargs), options.output, options.ext)
          report_progress(len(plotargs), len(plotargs),
                          options.output, options.ext)
          print('')
      ## clean out empty directories
      for root, dirs, files in os.walk(options.output):
          if not os.listdir(root):
              os.rmdir(root)
      ## add index.html files to all directories
      if options.ext in ['png', 'gif', 'svg']:
          print("Writing html index files...")
          width, height = options.size
          if use_mpl:
              width, height = [x * options.dpi for x in options.size]
          for path, dirs, files in os.walk(options.output):
              dirs, files = sorted(dirs), sorted(files)
              make_html_index(path, dirs, files, options.ext,
                              options.html_template, options.ncolumns_html,
                              width, height)
      if options.merge:
          merge_pdf(options)
function_tokens: def rootplot ( * args , * * kwargs ) : if 'config' in kwargs : write_config ( ) options = fill_options ( args , kwargs , scope = 'global' ) nfiles = len ( options . filenames ) ntargets = len ( options . targets ) if nfiles < 1 : raise TypeError ( "%s takes at least 1 filename argument (0 given)" % prog ) elif ntargets > 0 and nfiles > 1 : raise TypeError ( "%s cannot accept targets (%i given) when " "multiple files are specified (%i given)" % ( prog , ntargets , nfiles ) ) rootfiles = [ RootFile ( filename ) for filename in options . filenames ] #### Create the output directory structure if not options . noclean and os . path . exists ( options . output ) : shutil . rmtree ( options . output ) for path , folders , objects in walk_rootfile ( '' , rootfiles [ 0 ] , options ) : if not os . path . exists ( joined ( options . output , path ) ) : os . makedirs ( joined ( options . output , path ) ) #### Loop over plots to make, building the necessary calls plotargs = get_plot_inputs ( rootfiles , options ) call_lists = [ ] ndigits = int ( math . log10 ( len ( plotargs ) ) ) + 1 for i , ( filenames , targets ) in enumerate ( plotargs ) : argstring = ', ' . join ( [ "'%s'" % x for x in ( filenames + targets + options . configs ) ] ) reduced_kwargs = dict ( kwargs ) for key , value in reduced_kwargs . items ( ) : if key in global_opts : del reduced_kwargs [ key ] elif isinstance ( value , str ) : reduced_kwargs [ key ] = "'%s'" % value if 'numbering' in kwargs : reduced_kwargs [ 'numbering' ] = i + 1 optstring = ', ' . join ( [ '%s=%s' % ( key , value ) for key , value in reduced_kwargs . items ( ) ] ) if optstring : argstring = "%s, %s" % ( argstring , optstring ) plotpath , title , legentries = get_plotpath ( filenames , targets ) savepath = joined ( options . output , plotpath ) if 'numbering' in reduced_kwargs : dirs = savepath . split ( '/' ) dirs [ - 1 ] = str ( i + 1 ) . zfill ( ndigits ) + dirs [ - 1 ] savepath = '/' . join ( dirs ) call_vars = { 'argstring' : argstring , 'ext' : options . ext , 'savepath' : savepath } if use_mpl : call_vars [ 'trans' ] = options . transparent call_vars [ 'dpi' ] = options . dpi api_call = ( "figure, objects = " "plotmpl(%(argstring)s)" % call_vars ) save_call = ( "figure.savefig('%(savepath)s', " "transparent=%(trans)s, " "dpi=%(dpi)s)" % call_vars ) else : api_call = ( "canvas, objects = " "plot(%(argstring)s)" % call_vars ) save_call = "canvas.SaveAs('%(savepath)s.%(ext)s')" % call_vars call_lists . append ( [ api_call , save_call ] ) #### Create scripts for that make the API calls ext = options . ext output = options . output processors = options . processors call_statements = '\n\n' . join ( [ plotcall + '\n' + savecall for plotcall , savecall in call_lists ] ) allplots_script = allplots_template % locals ( ) call_statements = "" . join ( [ multi_call_template % ( plotcall , savecall ) for plotcall , savecall in call_lists ] ) allplots_multi_script = allplots_multi_template % locals ( ) write_to_file ( allplots_script , joined ( options . output , 'allplots.py' ) ) write_to_file ( allplots_multi_script , joined ( options . output , 'allplots_multi.py' ) ) #### Execute the calls if use_multiprocessing : original_dir = os . getcwd ( ) os . chdir ( options . output ) exec ( allplots_multi_script ) os . chdir ( original_dir ) else : for i , call_list in enumerate ( call_lists ) : make_calls ( * call_list ) report_progress ( i + 1 , len ( plotargs ) , options . output , options . ext ) report_progress ( len ( plotargs ) , len ( plotargs ) , options . output , options . ext ) print ( '' ) ## clean out empty directories for root , dirs , files in os . walk ( options . output ) : if not os . listdir ( root ) : os . rmdir ( root ) ## add index.html files to all directories if options . ext in [ 'png' , 'gif' , 'svg' ] : print ( "Writing html index files..." ) width , height = options . size if use_mpl : width , height = [ x * options . dpi for x in options . size ] for path , dirs , files in os . walk ( options . output ) : dirs , files = sorted ( dirs ) , sorted ( files ) make_html_index ( path , dirs , files , options . ext , options . html_template , options . ncolumns_html , width , height ) if options . merge : merge_pdf ( options )