2008-02-29

Plotting in matplotlib/pylab

by Forrest Sheng Bao http://fsbao.net

I like Python, the simple but elegant syntax. I can't love any other programming languages more than Python. So I prefer to do my scientific computing in Python. I am very happy to find Numpy/SciPy package. matplotlib/pylab makes it possible for me to visualize my results. Neat!

Here is my first plotting script using matplotlib/pylab:

#This software is a free software. 
#Thus, it is licensed under GNU General Public License.
#Python implementation to read U. Bonn's data and plot it
#Forrest Bao, Feb. 26

import sys,string

from numpy import *
from pylab import *

f1=open(sys.argv[1],'r')

data=[]
for line in f1.readlines():
data.append(map(int, line.split()))

x = range(0,len(data));
lines = plot(x, data);

setp(lines, linewidth=0.5)
#shrink_to_aspect(lines, fig_aspect=0.5)
axis('tight')

grid(True);
xlabel('sampling points');
ylabel('quantilized steps');
title(sys.argv[1][:-4]);

savefig('eps/'+sys.argv[1][:-4]+'.eps')
savefig('png/'+sys.argv[1][:-4]+'.png')

#show();

No comments: