User Tools

Site Tools


dev:plotting_elem_counts

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:

sudo apt-get install python-matplotlib

Example usage:

./plot_element_counts.py /tmp/xxx/tbd/data.dat “a nice title” “Data” “Creg” “Dreg”

#!/usr/bin/env python
 
# This script plots the counts of the specified elements against AEPS, 
# 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
        header = inFile.readline().split()
        header.remove("#") # there is a column named as "# AEPS", bad
        AEPS_index = header.index("AEPS")
        lines = inFile.readlines()
        AEPS = []
        for l in lines:
            entries = l.split()
            AEPS.append(entries[AEPS_index])
        ##############################
 
 
        # Read data lines of file, get element counts, make plots for each
        fig_index = 0
        for elem in elem_names:
            col_index = header.index(elem)
            counts = []
 
            for l in lines:
                entries = l.split()
                counts.append(entries[col_index])
 
            # Make plots for this Element
            fig = plt.figure(fig_index)
            fig_index += 1
            plt.plot(AEPS, counts)
            plt.xlabel('AEPS')
            plt.ylabel("Number of " + elem)
            plt.title(plot_title)
 
        # Show all figures/plots
        plt.show()
 
# When run as a script
if __name__ == "__main__":
    if len(sys.argv) < 4:
        print "Usage: <tbd data file> <plot_title> <list of Element names>"
    else:
        plot_mfs_data(sys.argv[1], sys.argv[2], sys.argv[3:])
dev/plotting_elem_counts.txt · Last modified: 2014/10/26 21:01 by jvick3