- not so Frequently Asked Questions -
not so FAQ
Gnuplot uses four coodinates to define positions of arbitrary lines, arrows, texts, and a legend. Those are called as "first", "second", "graph", and "screen". The "first" coodinate is the left Y-axis and the bottom X-axis. The "second" is the right Y2-axis and the top X2-axis. The "graph" coodinate is a relative position in the graph frame. The "screen" coodinate is a relative position in the whole screen (paper). The defaut is the "first" coordinate. The position can be specified by the syntax graph x, screen y .
The next example is to write a text at the origin of each coodinate.
gnuplot> set label "(0,0) first" at first 0, first 0 gnuplot> set label "(0,0) graph" at graph 0, graph 0 gnuplot> set label "(0,0) screen" at screen 0, screen 0
The "first" label is placed at the center of the graph. The origin of the graph coordinate locates at the left bottom corner. The top right corner is the coordinate (1,1). The location defined in the graph coordinate is relative to the graph size. For example graph 0.5, graph 0.5 is always the center in the graph border. The origin of the "screen" coordinate is the left bottom corner and (1,1) is the top right corner of the screen (paper). This coordinate is not affected by the size of plot.
A label defined in the "first" coordinate moves when the range of X and Y axes are changed, but it does not move if the coordinate is "graph" or "screen".
gnuplot> set xrange [-10:4] gnuplot> set yrange [-10:4] gnuplot> replot
Let's move the whole graph toward right and top. The command set origin x,y changes the origin of the graph. The x and y are given in the "screen" coordinate.
gnuplot> set origin 0.2,0.2 gnuplot> replot
The origin given in the screen coordinate is always left bottom, but the origin of the graph coordinate moves when origin is changed
To explain something, an arrow is often used in a figure. Gnuplot makes arrows or lines by set arrow command. The simplest syntax is set arrow from 1,2 to 2,4 , which shows an arrow from (1,2) to (2,4). The coordinate is the "first" coordinate if it is not specified, so that the location depends on the X and Y axis values. To make arrows independently of the axes, use the graph or screen coordinates.
Gnuplot assigns an integer number for each arrows (if not specified). The first one is "1" and the second is "2", so on. Those numbers are used to redefine the arrow or remove it. The syntax is the same as set label command.
gnuplot> set arrow from 0,0 to 1,1 gnuplot> set arrow from 0,0 to 1,2 gnuplot> set arrow from 0,0 to 1,3
The first arrow (from origin to (1,1)) becomes No.1, and the next is No.2. To remove No.2 and change the end point of No.3:
gnuplot> set noarrow 2 gnuplot> set arrow 3 to 1,5
It is also possible to define the arrow numbers like set arrow 1 . The defined arrows can be confirmed by show arrow command. If an option nohead is given, an arrow without a head is drawn. You can change the width or linestyle by lw (linewidth) and ls (linesyle) options.
Sometimes the coordinates for arrows are not exactly known before some function is plotted. If the function is a simple one, try the next method.
Firstly define the function to be plotted. Functions y=x**2 and y=1-(1-x)**2 are used here as an example. When one wants to draw an arrow between these two functions at X=0.5, one needs the Y values at X=0.5. The two functions are defined as follows.
gnuplot> f(x)=x*x gnuplot> g(x)=1-(1-x)*(1-x)
To make an arrow at X=0.5, those functions are used at the definition of the arrow.
gnuplot> set arrow 1 from 0.5,f(0.5) to 0.5,g(0.5) gnuplot> plot f(x),g(x)
In this method the coordinates are calculated at the set arrow command execution, so those values are not changed automatically when the functions f(x) and g(x) are changed. If the functions are re-defined, one needs to re-define the arrow too.
(Probably) It is impossible to make an arrow with two heads (both sides) easily. To do this, define two arrows with the opposite direction.
gnuplot> set arrow 1 from 1,2 to 1,4 gnuplot> set arrow 2 to 1,2 from 1,4