Plotting Data

One of the first things you will need to figure out how to do in this course is plot data. If you are using Matlab, then this will be very easy. The following is a transcript of a matlab session in which I plot a graph and print it.
MINKOWSKI.MIT.EDU% matlab &

>> x = [0:.01:pi];
>> y = sin(x);
>> plot(x,y)
>> print
This is a pretty bare-bones plot, and it is missing things that every plot should have: Here is an example of a plot with these elements:
x = [0:.2:pi];
y = sin(x);
y2 = cos(x);
clf;
plot(x,y,'bo');
hold on
h1 = plot(x,y,'b');
plot(x,y2,'ro');
h2 = plot(x,y2,'r');
legend([h1,h2],{'y=sin(x)','y=cos(x)'})
xlabel('x');
ylabel('y');
title('trig functions')

Here is an example of a loglog plot:
x = [0:.1:3];
y = x.^2;
z = x.^3;
clf
loglog(x,y,'bo')
hold on
h1 = loglog(x,y,'b');
loglog(x,z,'ro');
h2 = loglog(x,z,'r');
legend([h1,h2],{'x^2','x^3'})
grid on

There are many ways to plot and print data even if you are not using Matlab. I hope that some student in the class will find an easy way to do this from Java. Until then, let me tell you about an old-fashioned approach to printing: Gnuplot . Among other things, Gnuplot can be used to plot and print data stored in a file. For an example, I've stored data in the file gnuplot.dat, which you may download and examine. Here is a transcript of how I plotted and printed this data using Gnuplot (gnuplot.dat was in my current directory).
MINKOWSKI.MIT.EDU% gnuplot

	G N U P L O T
	Linux version 3.7
	patchlevel 1
	last modified Fri Oct 22 18:00:00 BST 1999

	Copyright(C) 1986 - 1993, 1998, 1999
	Thomas Williams, Colin Kelley and many others

	Type `help` to access the on-line reference manual
	The gnuplot FAQ is available from
	

	Send comments and requests for help to 
	Send bugs, suggestions and mods to 


Terminal type set to 'x11'
gnuplot> plot "gnuplot.dat"
gnuplot> set data style linespoints
gnuplot> replot
gnuplot> set output "| lpr"
gnuplot> set terminal postscript
Terminal type set to 'postscript'
Options are 'landscape noenhanced monochrome dashed defaultplex "Helvetica" 14'
gnuplot> replot
gnuplot> set output "| lpr"
gnuplot> 
I learned how to do this from the instructions at http://www.cs.uni.edu/Help/gnuplot/ . I'm sure you can find more information on the web. Finally, if you wanted to plot or print the data from this file in Matlab, you would type:
>> load gnuplot.dat
>> x = gnuplot(:,1);
>> y = gnuplot(:,2);
>> plot(x,y)
>> print

Dan Spielman
Last modified: Thu Feb 5 12:45:23 EST 2004