Source code for scipub

"""
Script that makes two plots of the same data contained in the F2files directory.

The first plot basically uses all the default settings in matplotlib, and the 
second shows what you can do with just a little extra effort.

Below is a slightly modified version of the metadata and instructions given to
me.  The details are not important. 

	"In all files in the directory F2files, the first column is stream length 
	(x-axis) and the THIRD column is prover time (y-axis). These are the only 
	two columns relevant to the plots.

	"Each file corresponds to a different "line" in the graph. There are three 
	files: one for the multiround prover, one for the single round prover 
	without FFT techniques, and one for the single round prover with FFT 
	techniques.  The file names say which is which, and the legend should 
	identify the lines accordingly."

Usage:  python scipub.py

Author:  Elaine Angelino <elaine at eecs dot harvard dot edu>

Copyright 2011

"""

import os

import tabular as tb

import pylab


[docs]def naive_plot(root, fout): """ Make a naive plot of the data using matplotlib's default settings. **Parameters** **root** : str Name of the input directory containing the data files. **fout** : str Name of output file for matplotlib figure. Use an extension like '.pdf' or '.png'. """ pylab.clf() flist = [f for f in os.listdir(root) if f.endswith('.txt')] legend = [f.split('.')[0] for f in flist] for f in flist: fname = os.path.join(root, f) print '\nLoading data from', fname a = tb.tabarray(SVfile=fname) # these are the column names provided in the file names = a.dtype.names # we want to plot the third column versus the first column x = a[names[0]] y = a[names[2]] pylab.loglog(x, y) pylab.title('Time to create proof') pylab.xlabel('n') pylab.ylabel('Time (s)') pylab.legend(legend) pylab.savefig(fout)
[docs]def make_plot(root, flist, fout, legend, marker_list, color_list): """ Make an effective plot in matplotlib by specifying custom settings. **Parameters** **root** : str Name of the input directory containing the data files. **flist** : list of strings List of the names of the data files in the input directory. Their order gives the order in which we plot the lines. We want control over this in designing a legend. **fout** : str Name of output file for matplotlib figure. Use an extension like '.pdf' or '.png'. **legend** : list of strings Labels to appear in the legend. We specify these by hand for greater clarity. Specify one label corresponding to the data for each file. **marker_list** : list of strings Specify a different marker shape for plotting data for each file. **color_list** : list of strings Specify a different color for plotting data for each file. """ pylab.clf() # we plot the data from each file with a different marker for (f, marker, color) in zip(flist, marker_list, color_list): fname = os.path.join(root, f) print '\nLoading data from', fname a = tb.tabarray(SVfile=fname) # these are the column names provided in the file names = a.dtype.names # we want to plot the third column versus the first column x = a[names[0]] y = a[names[2]] pylab.loglog(x, y, marker=marker, markersize=10, color=color, linestyle='-') pylab.title('Time to create proof', fontsize=20) pylab.xlabel('n', fontsize=20) pylab.ylabel('Time (s)', fontsize=20) pylab.xticks(fontsize=20) pylab.yticks(fontsize=20) pylab.legend(legend, loc='upper left') pylab.savefig(fout)
if __name__ == '__main__': root = 'F2files' print 'Generating a naive plot with default matplotlib settings' naive_plot(root, root + '_naive.png') flist = ['uniF2NoFFT.txt', 'uniF2withFFT.txt', 'multiF2.txt'] legend = ['One Round without FFT', 'One Round with FFT', 'Multiround'] marker_list = ['^', 'o', 's'] color_list = ['b', 'k', 'r'] print 'Generating a better plot by customizing matplotlib settings' make_plot(root, flist, root + '.png', legend, marker_list, color_list, axis)