Skip to content

Instantly share code, notes, and snippets.

@markjlorenz
Last active January 2, 2016 23:49
Show Gist options
  • Save markjlorenz/8379111 to your computer and use it in GitHub Desktop.
Save markjlorenz/8379111 to your computer and use it in GitHub Desktop.
gnuplot examples
#!/usr/bin/env gnuplot
set datafile separator ","
file="`echo $plot_file`" # make sure to set the $plot_file environment varible first
f(x) = m * x**b # fit to trend matching mx^b
m = 5 # start the 'm' search at 5
b = 2 # start the 'b' search at 2
fit f(x) file via m,b
title_f(m, b) = sprintf('f(x) = %.2f*x^%.2f', m, b) # display the final m and b values on the chart
plot f(x) t title_f(m,b), file
pause mouse keypress
#!/usr/bin/env gnuplot
file_name = "accel-and-time.dat"
data_set_size = system("cat ".file_name." | wc -l")
set datafile separator ','
binc(x,s) = s*(int(x/s)+0.5)
bin_width = 0.025
set boxwidth bin_width
# $1, $2, and $3 plot histograms for columns 1-3 of the datafile
plot file_name u (bin($1,bin_width)):(1.0/(bin_width*data_set_size)) smooth frequency with boxes
pause mouse keypress
plot file_name u (bin($2,bin_width)):(1.0/(bin_width*data_set_size)) smooth frequency with boxes
pause mouse keypress
plot file_name u (binc($3,bin_width)):(1.0/(bin_width*data_set_size)) smooth frequency with boxes
pause mouse keypress
#!/usr/bin/env gnuplot
set term dumb # use the terminal to plot
set datafile separator "," # CSV data
#set view equal xyz # plot axies should have the same scale
#splot "/dev/stdin" # 3D plot
plot "/dev/stdin" using 1:3 # use columns 1 and 3 of the data for the plot (gnuplot is 0 indexed)
plot "/dev/stdin" pointtype 24 # 2D plot, using "X" as the marker
plot "/dev/stdin" with lines # Line chart
#pause mouse keypress # dont' immediatly close the plot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment