Learn Gnuplot in an Hour Free and Open Software How to Plot Practically Anything Practically Anyway
What is Gnuplot? ● Plotting Software – command-line based ● Unix / Linux ● Mac OS X ● Windows Dialog Box Data Functions
Why Gnuplot? ● Fun – Had To Be Fun ● All Common Graphic Formats - jpg, gif, png (and some not so common) ● Readily Available ● Reliable ● Free – Now and Forever ● No Initial Learning Curve
The Most Common Commands ● Set (unset reset) ● Plot (replot splot) ● Call ● Help ● History ● Load Usage 90 % ● Print ● Save ● Show ● Test
What We're Going to Do (1 of 2) Interactive Mode ● Plot Functions ● Line Width and Line Type ● Set ● X- and Y- Labels / Ranges ● Grid ● Title ● Key (legend) ● Save and Load Files (by the book) ● Save Files (by hook-or-by-crook) History Command
What We're Going to Do (2 of 2) 'Scriptive' Mode ● Plot Data ● Data Format / Separators ● Line Width and Line Type (revisited) ● Test Command ● Terminals ● Export Graphs
Interactive Mode (1 of 10) Begin at the Beginning ● Open a Terminal ● cd Desktop ● gnuplot G N U P L O T Version 4.4 patchlevel 0 last modified March 2010 System: Linux generic Copyright (C) , 1998, 2004, Thomas Williams, Colin Kelley and many others gnuplot home: faq, bugs, etc: type "help seeking- assistance" immediate help: type "help" plot window: hit 'h' Terminal type set to 'x11' gnuplot> Version 4.4 ?
Interactive Mode (2 of 10) Your first plot! ● gnuplot> plot sin(x)
Interactive Mode (3 of 10) Modify the Ranges: x and y ● gnuplot> plot [-6:6] [-1.25:1.25] sin(x)
Interactive Mode (4 of 10) Modify the Grid and Title ● gnuplot>set grid ● gnuplot>set title 'Sinusoids' ● gnuplot> replot
Interactive Mode (5 of 10) Modify the X-Label and Y-Label ● gnuplot>set xlabel 'X-Values' ● gnuplot>set ylabel 'Amplitude' ● gnuplot> replot
Interactive Mode (6 of 10) Add a 2 nd Function ● gnuplot>plot [-6:6] [-1.25:1.25] sin(x), cos(x) Don't forget the comma.
Interactive Mode (7 of 10) Modify the Plot Command - Width ● gnuplot>plot [-6:6] [-1.25:1.25] sin(x) linewidth 3, cos(x) linewidth 3 Change the width of the lines.
Interactive Mode (8 of 10) Modify the Plot Command - Color ● gnuplot>plot [-6:6] [-1.25:1.25] sin(x) linetype 1 linewidth 3, cos(x) linetype 3 linewidth 3
Interactive Mode (9 of 10) Modify the Plot Command - Key ● gnuplot>plot [-6:6] [-1.25:1.25] sin(x) linetype 1 linewidth 3 title "Sin", cos(x) linetype 3 linewidth 3 title "Cos"
Interactive Mode (1 of 2) Save and Load –.gp files (.plt Windows) ● gnuplot> save 'temp.gp' ● gnuplot > load 'temp.gp' ● Open 'temp.gp' In gedit – (OMG) Save your work. Load and run your work. ● gnuplot> show all Details Galore!.
Interactive Mode (2 of 2) The History Command ● gnuplot> history quiet What happened? set grid set xlabel "X-Values" set ylabel "Amplitude" set title "Sinusoids" plot [0:6.28] [-1.6:1.6] sin(x) with lines linewidth 4 title "Sin", cos(x) with lines linewidth 4 title "Cos" history quiet Copy and paste into gedit. Remove unwanted lines. Save as 'filename.gp' ● gnuplot> history
● Plot Functions ● Line Width and Line Type ● Set ● X- and Y- Labels / Ranges ● Grid ● Title ● Key (legend) ● Save and Load Files (by the book) ● Save Files (History command) Interactive Mode (summary)
Scriptive Mode (1 of 9) View the Data ● In gedit open the Sinusoids.dat file # Sinusoids.dat contains white-space separated data etc.
Scriptive Mode (2 of 9) View the gnuplot file ● In gedit open the SinusoidsOne.gp file # SinusoidsOne.gp calls the white-space separated data file set grid # No data separator is necessary in this file. set title "With White-Space Data File" Plot [ ] [-1.75:1.25] "Sinusoids.dat" using 1:2 title "Sin" Calls data file Refers to columns 1 and 2
Scriptive Mode (3 of 9) Run the gnuplot file “scriptively” ● Open a terminal ● cd Desktop ● gnuplot -persist 'SinusoidsOne.gp'
Scriptive Mode (4 of 9) Modify the gnuplot file to include Lines, Points, Linepoints ● In gedit remark-out the first plot command and run with Points ● In gedit remark-out the first plot command and run with Lines ● In gedit remark-out the first plot command and run with Linespoints
Scriptive Mode (5 of 9) View the CSV Data ● In gedit open the Sinusoids.cvs file # Sinusoids.dat contains comma-separated data -3.14,0, ,-0.1, ,-0.2, ,-0.3, ,-0.39, ,-0.48, ,-0.57, ,-0.65,-0.76 etc.
Scriptive Mode (6 of 9) View the gnuplot file ● In gedit open the SinusoidsTwo.gp file # SinusoidsTwo.gp calls the CSV separated data file set grid set datafile separator "," # To accommodate the commas in the data file. set title "With CSV Data File" Plot [ ] [-1.75:1.25] "Sinusoids.csv" using 1:2 title "Sin” Calls data file Refers to columns 1 and 2
Scriptive Mode (7 of 9) Modify the gnuplot file to include Lines, Points, Linepoints ● In gedit remark-out the first plot command and run with either Points, Lines or Linespoints
Scriptive Mode (8 of 9) Add a 2 nd and 3 rd Function ● In gedit open SinusoidsThree.gp ● gnuplot -persist 'SinusoidsThree.gp' ● Review plot command in file Note type and size of curves: Lines, Points and a combination.
Scriptive Mode (9 of 9) Review of SinusoidsThree.gp # SinusoidsThree.gp uses a mathematical formula – 'data transformation' # And used "lines" for the Sin, "Points" for Cos and "Linespoint" for the Difference. set grid set title "Notice!! Sin in Lines \nCos in Points \n Difference in Linespoints." Plot [ ] [-1.75:1.75] "Sinusoids.dat" using 1:2 with lines linetype 1 title "Sin", \ "Sinusoids.dat" using 1:3 with points pointsize 2 linetype 3 title "Cos", \ "Sinusoids.dat" using 1:($2 -$3) with linespoints linewidth 2 linetype 6 title "Sin - Cos" # Note difference: Lines, Points and Linespoints # Note different Line and Point Sizes # Remember can change x-range for better view of Points and Lines # Note also the formula: using 1:($2-$3)
Test Command Reviewing Color and Linetype ● In gnuplot type gnuplot>test ● Open Test.GIF by double clicking on it ● Compare them
Terminals (1 of 2) ● In gnuplot type: gnuplot>show terminal ● In gnuplot type: gnuplot>set terminal gif ● In gnuplot type: gnuplot>show terminal ● In gnuplot type: gnuplot>set terminal x11 ● Some Terminals: gif, png, jpg, svg, ps (re: LaTeX) Set terminal back to original setting
Terminals (2 of 2) GIF Example ● In gedit open SinusoidsGIF.gp ● Review SinusoidsGIF.gp ● gnuplot SinusoidsGIF.gp SinusoidsGIF.gp includes: set terminal gif set output
● Plot Data ● Data Format / Separators ● Line Width and Line Type (revisited) ● Test Command ● Terminals ● Export Graphs Interactive Mode (summary)
What's Ahead Some Topics Not Covered ● Abbreviations ● Animation ● Arrows and Labels ● Colors (4 other methods) ● Fonts ● Data Smoothing ● Help ● Macros ● Missing Data ● Multi-plots ● Numerical Formats ● Polar Coordinates ● Redirection ● Statistics ● Size and Ratio ● Time Series
Websites for Follow-up ● Gnuplot Home Page ● Gnuplot Demo Pages ● Demo of Demo Pages copy, paste and run Demo_4.4/histograms in gnuplot copy, paste and run Demo_4.4/control models in gnuplot (adjust x-range 0 to 10 and y-range 0 to 1.8) copy, paste and run Demo_4.4/finance in gnuplot
Additional Websites, etc. ● Gnuplot Newsgroup comp.graphics.apps.gnuplot ● Gnuplot mailing list ● More Advanced gnuplot info ● gnuplot_QuickReference.pdf
The End ! Thank You