Skip to content

Instantly share code, notes, and snippets.

@biplab37
Last active April 26, 2020 05:22
Show Gist options
  • Save biplab37/af3ab7ae7b1e77ab134e357f171cf2a4 to your computer and use it in GitHub Desktop.
Save biplab37/af3ab7ae7b1e77ab134e357f171cf2a4 to your computer and use it in GitHub Desktop.
Creating Plots

Plotting in Gnuplot


Suppose you want to plot your data in the file name 'data.dat' and fit it with linear regression then add the code below in a file say 'plot.gnuplot'

	#!/usr/bin/gnuplot
	set terminal png
	set output 'image.png'

	set title 'Plot' font 'Hack,12'
	set xlabel 'x-axis with Greek symbol alpha {/Symbol a}' font 'Hack,11'
	set ylabel 'y-axis_{subscript}^{superscript}' font 'Hack,11'
	set tics font ',9'

	f(x) = a + b*x

	fit f(x) 'data.dat' via a,b

	plot 'data.dat' title 'data points', f(x) title 'fitted curve'

to run the file just run the command in the terminal

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