User Tools

Site Tools


dev:plotting_elem_counts

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
dev:plotting_elem_counts [2014/10/26 20:54] jvick3dev:plotting_elem_counts [2014/10/26 21:01] (current) jvick3
Line 1: Line 1:
-The //plot_element_counts.py// script:+The //plot_element_counts.py// script.  If you get an error that it cannot find the module "matplotlib" or something, it's probably not installed.  This fixes that on Ubuntu:
  
- #!/usr/bin/env python+sudo apt-get install python-matplotlib
  
- # Reads .mfs files in a directory and makes plots of +Example usage:
- # particular elements (Data, Isolator) in them +
- # Work-in-progress.+
  
- import sys +./plot_element_counts.py /tmp/xxx/tbd/data.dat "a nice title" "Data" "Creg" "Dreg"
- import matplotlib.pyplot as plt+
  
- # Idea: keep a mapping somewhere (file?) of Element name to color +<code python> 
- #      to use with plot+#!/usr/bin/env python
  
- def plot_mfs_data(filePath, plot_title, elem_names): +# This script plots the counts of the specified elements against AEPS,  
-     with open(filePath, "r") as inFile:+# each plot having the specified title. 
 + 
 +import sys 
 +import matplotlib.pyplot as plt 
 + 
 +# Idea: keep a mapping somewhere (file?) of Element name to color 
 +#      to use with plot 
 + 
 +def plot_mfs_data(filePath, plot_title, elem_names): 
 +    with open(filePath, "r") as inFile:
                  
-         # Read header and AEPS column +        # Read header and AEPS column 
-         header = inFile.readline().split() +        header = inFile.readline().split() 
-         header.remove("#") # there is a column named as "# AEPS", bad +        header.remove("#") # there is a column named as "# AEPS", bad 
-         AEPS_index = header.index("AEPS"+        AEPS_index = header.index("AEPS"
-         lines = inFile.readlines() +        lines = inFile.readlines() 
-         AEPS = [] +        AEPS = [] 
-         for l in lines: +        for l in lines: 
-             entries = l.split() +            entries = l.split() 
-             AEPS.append(entries[AEPS_index]) +            AEPS.append(entries[AEPS_index]) 
-         ##############################+        ##############################
                  
      
-         # Read data lines of file, get element counts, make plots for each +        # Read data lines of file, get element counts, make plots for each 
-         fig_index = 0 +        fig_index = 0 
-         for elem in elem_names: +        for elem in elem_names: 
-             col_index = header.index(elem) +            col_index = header.index(elem) 
-             counts = []+            counts = []
  
-             for l in lines: +            for l in lines: 
-                 entries = l.split() +                entries = l.split() 
-                 counts.append(entries[col_index])+                counts.append(entries[col_index])
  
-             # Make plots for this Element +            # Make plots for this Element 
-             fig = plt.figure(fig_index) +            fig = plt.figure(fig_index) 
-             fig_index += 1 +            fig_index += 1 
-             plt.plot(AEPS, counts) +            plt.plot(AEPS, counts) 
-             plt.xlabel('AEPS'+            plt.xlabel('AEPS'
-             plt.ylabel("Number of " + elem) +            plt.ylabel("Number of " + elem) 
-             plt.title(plot_title)+            plt.title(plot_title)
                        
-         # Show all figures/plots +        # Show all figures/plots 
-         plt.show()+        plt.show()
                  
- # When run as a script +# When run as a script 
- if __name__ == "__main__": +if __name__ == "__main__": 
-     if len(sys.argv) < 4: +    if len(sys.argv) < 4: 
-         print "Usage: <tbd data file> <plot_title> <list of Element names>" +        print "Usage: <tbd data file> <plot_title> <list of Element names>" 
-     else: +    else: 
-         plot_mfs_data(sys.argv[1], sys.argv[2], sys.argv[3:]) +        plot_mfs_data(sys.argv[1], sys.argv[2], sys.argv[3:]) 
-    +</code> 
  
dev/plotting_elem_counts.1414356841.txt.gz · Last modified: 2014/10/26 20:54 by jvick3