To draw a simple line graph first place the points to draw in a separate file in this case named "gnuplot.data"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 0 | |
1 1 | |
2 4 | |
3 9 | |
4 16 | |
5 25 | |
6 36 | |
7 49 | |
8 64 | |
9 81 |
Now create the gnuplot script:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/gnuplot | |
set title "Plot x^2" | |
set xlabel "X" | |
set ylabel "Y" | |
set ytics "10" | |
plot "gnuplot.data" title "" with lines | |
pause -1 "Hit any key to continue" |
The pause line at the end keeps the gnuplot from flashing the graph and then immediately exiting. When you execute gnuplot you'll see the following:
There is a ton more you can do with gnuplot like generate png files, create different types of graphs, but I've found that as a simple programming tool this gets me 90% there. For more information checkout the gnuplot homepage. Happy plotting