Difference between revisions of "Gnuplot"
Line 13: | Line 13: | ||
gnuplot> plot sin(x) | gnuplot> plot sin(x) | ||
− | [[File:gnuplot_tutorial_pic_001.png| | + | [[File:gnuplot_tutorial_pic_001.png|400px]] |
Note that <code>x</code> is a special Multiple functions can be plotted on the same graph, just separate each with a comma | Note that <code>x</code> is a special Multiple functions can be plotted on the same graph, just separate each with a comma | ||
Line 19: | Line 19: | ||
gnuplot> plot sin(x), cos(x) | gnuplot> plot sin(x), cos(x) | ||
− | [[File:gnuplot_tutorial_pic_002.png| | + | [[File:gnuplot_tutorial_pic_002.png|400px]] |
We control the what and how our plot is displayed by setting ''options''. Options are set with the <code>set</code> command. For example, to set the graph title, we set the <code>title</code> option to a string containing the title. | We control the what and how our plot is displayed by setting ''options''. Options are set with the <code>set</code> command. For example, to set the graph title, we set the <code>title</code> option to a string containing the title. | ||
Line 29: | Line 29: | ||
gnuplot> replot # redraw the previous plot with new options | gnuplot> replot # redraw the previous plot with new options | ||
− | [[File:gnuplot_tutorial_pic_003.png| | + | [[File:gnuplot_tutorial_pic_003.png|400px]] |
Other important options include <code>xlabel</code> (the x-axis label), <code>ylabel</code> (the y-axis label) and <code>key</code> (sets the position of the legend). The legend is located in the top-right corner of the graph by default, which is in the way in the example above. To label the axis and move the key, | Other important options include <code>xlabel</code> (the x-axis label), <code>ylabel</code> (the y-axis label) and <code>key</code> (sets the position of the legend). The legend is located in the top-right corner of the graph by default, which is in the way in the example above. To label the axis and move the key, | ||
Line 37: | Line 37: | ||
gnuplot> set key top left | gnuplot> set key top left | ||
− | [[File:gnuplot_tutorial_pic_004.png| | + | [[File:gnuplot_tutorial_pic_004.png|400px]] |
==Creating Pictures== | ==Creating Pictures== | ||
==Gnuplot Scripts== | ==Gnuplot Scripts== |
Revision as of 18:10, 12 March 2012
Gnuplot is a terminal based plotting application. This means that you interact with gnuplot by typing commands at a prompt. This turns out to be very convenient, because it means that you can always save or create a gnuplot configuration into a plain text file.
Plotting
gnuplot is a program created to plot stuff. You can plot functions or data. There are two commands for plotting, plot
and splot
. plot
is used to plot 2D functions while splot
is used to plot 3D functions.
basic plotting
The plot
command has the following form
gnuplot> plot [ function | 'filename' ] [ modifiers ]
gnuplot has great support for all common (and many uncommon) functions. For example, to plot sin(x),
gnuplot> plot sin(x)
Note that x
is a special Multiple functions can be plotted on the same graph, just separate each with a comma
gnuplot> plot sin(x), cos(x)
We control the what and how our plot is displayed by setting options. Options are set with the set
command. For example, to set the graph title, we set the title
option to a string containing the title.
gnuplot> set title "Sine and Cosine"
Notice that the graph does not change after you set the title option. Gnuplot will not redraw the graph until we either issue another plot
command, or tell it to replot what we previously plotted with the ...replot
command.
gnuplot> replot # redraw the previous plot with new options
Other important options include xlabel
(the x-axis label), ylabel
(the y-axis label) and key
(sets the position of the legend). The legend is located in the top-right corner of the graph by default, which is in the way in the example above. To label the axis and move the key,
gnuplot> set xlabel "time (s)" gnuplot> set ylabel "current (A)" gnuplot> set key top left