Plotting Data with GnuPlot

If you have a very, very large file with a lot of data points in it, it might be painfully slow to try to open the file in Excel in order to make a plot of a subset of the data. We have a 2.3GB file of XY points where we want to plot only a couple columns. In this case, gnuplot works really well.

Here's a small sample of what our data looks like:

Vcomp\<0\> X,Vcomp\<0\> Y,Vcomp\<1\> X,Vcomp\<1\> Y
0,0.6003082534854087,0,0.6003082534854087
5e-10,0.6003081861583949,5e-10,0.6003081861583949
1.298302393395129e-08,0.5952218991966104,1.307352943945348e-08,0.5951725771787909
1.305725888381056e-08,0.5894227566357512,1.314951811229992e-08,0.5892744360671713
1.319417783768245e-08,0.5843579406990581,1.328141484050453e-08,0.5844113630690041
1.352960232657428e-08,0.5779101742903839,1.361981039568891e-08,0.5779361131760281

In the actual data file, there are 4096 X and Y columns and over 100,000 lines in each column.

Our first step is to make a plot file to use in gnuplot. Ours is called make_plot.gp and looks like this:

# Set size of output image
set terminal png size 1200,800

# Set name of output file.  The quotes are required
set output "out.png"

# Set style of plot.  We want lines
set style data lines

# Set how the data is separated in the file
set datafile separator ","

# Set the title of the plot
set title "Analog Block 3 Reduced Sim 2"

# The actual data to plot
# using 1:2 means column 1 is on the X axis and column 2 is on the Y
# with lines means to connect the points with lines
# t "Col 0 XY" is the title for the legend

# If you want to plot multiple xy pairs on the same graph, do this

plot "Analog_block_3_reduced_sim2.csv" using 1:2 with lines t "Col 0 XY", \
 "" using 3:4 t "Col 1 XY", \
 "" using 5:6 t "Col 2 XY"

Then we just start gnuplot and load our plot file.

yo:simulation $ gnuplot

	G N U P L O T
	Version 4.6 patchlevel 1    last modified 2012-09-26 
	Build System: Darwin x86_64

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

	gnuplot home:     http://www.gnuplot.info
	faq, bugs, etc:   type "help FAQ"
	immediate help:   type "help"  (plot window: hit 'h')

Terminal type set to 'aqua'
gnuplot> load "make_plot.gp"

When it finishes, which can take a few minutes, there will be a file in your directory called out.png which is our plot. A sample of one of our plots is below.

our output file
Updated: December 2013