Skip to content

Instantly share code, notes, and snippets.

@fearofcode
Created February 25, 2013 22:59
Show Gist options
  • Save fearofcode/5034126 to your computer and use it in GitHub Desktop.
Save fearofcode/5034126 to your computer and use it in GitHub Desktop.
sample gnuplot script for plotting multiple time series together, each with different colors
# resulting image: http://i.imgur.com/E5CsReh.png
# create a 1680x1050 image using Arial, 12pt
set terminal pngcairo enhanced font "arial,12" fontscale 1.0 size 1680, 1050
# write to the file 'multiplot_test.png'
set output 'multiplot_test.png'
# turn key off since we will be plotting many different
unset key
# tell gnuplot we are plotting time data formatted like Year-month-day
set xdata time
set timefmt "%Y-%m-%d"
# set colors for each segment we are drawing
set style line 1 linewidth 3 linecolor rgb "green"
set style line 2 linewidth 3 linecolor rgb "black"
set style line 3 linewidth 3 linecolor rgb "red"
# plot the input file using the line styles defined above
plot 'test.dat' i 0 u 1:2 w lines ls 1,\
'test.dat' i 1 u 1:2 w lines ls 2,\
'test.dat' i 2 u 1:2 w lines ls 3
"trade 1"
2012-01-08 20
2012-01-09 21
2012-01-10 22
2012-01-11 23
2012-01-12 22
"out of market"
2012-01-12 22
2012-01-13 23
2012-01-14 22
2012-01-15 21
2012-01-16 22
"trade 2"
2012-01-16 22
2012-01-17 21
2012-01-18 15
2012-01-19 13
@pcolby
Copy link

pcolby commented Sep 15, 2024

I found this example incredibly useful! Thank you!

With recent gnuplot versions, the plot command can be simplified to just one line:

plot for [i=0:*] 'test.dat' i i u 1:2 w lines ls i+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment