Building arrows with gnuplot

I have data generated in a simulation. The generated data file looks something like this:

1990/01/01 99 1990/01/02 92.7 1990/01/03 100.3 1990/01/04 44.2 1990/01/05 71.23 ... 2100/01/01 98.25 

I can create a diagram (trivially) by simply issuing the (long version) command:

 plot "simulation.dat" using 1:2 with line 

I want to add a third column that will add arrow information. The encoding for the third column will look like this:

  • 0 => there is no arrow for this x axis value
  • 1 => UPWARD pointer arrow indicated for x axis value
  • 2 => DOWNWARD arrow to draw x-axis value

I'm just starting to learn gnuplot and would appreciate help on how I can use gnuplot to create arrows on the first chart?

+6
gnuplot
source share
3 answers

I don’t think there is an automatic way to create all your arrows at the same time based on the third column. You will need to do the following for each arrow that you want:

 set arrow xval1,yval1 to xval2,yval2 

You can also use relative arrows.

 set arrow xval1,yval1 rto 1,0 

This will draw a horizontal arrow from xval1, yval1 to (xval1 + 1), yval1

There are many options related to the set arrow command :

+3
source share

If you don’t need the arrow head, you can try the pulse style (with pulses, not with lines) (If you still want the lines to be on top, you can display twice).

If you really need arrows, the following might help: it uses a for loop (or sorts) to add vertical arrows to the plot.

Gnuplot script, for looping inside or adding an existing chart

In particular:

create a simloop.gp file that looks like this:

 count = count+1 #save the count to count.gp system 'echo '.count.' > count.gp' #load the simloop shell system "./simloop.sh" #draw the arrow load 'draw_arrow.gp' if(count<max) reread 

Then create a simloop.sh file that looks something like this.

 #!/bin/bash #read the count count=$(awk -F, '{print $1}' count.gp) #read the file xcoord=$(awk -v count=$count -F, 'BEGIN{FS=" ";}{ if(NR==count) print $1}' simulation.dat) ycoord=$(awk -v count=$count -F, 'BEGIN{FS=" "}{ if(NR==count) print $2}' simulation.dat) dir=$(awk -v count=$count -F, 'BEGIN{FS=" "}{ if(NR==count) print $3}' simulation.dat) #choose the direction of the arrow if [ \"$dir\" == \"0\" ]; then echo '' > draw_arrow.gp fi if [ \"$dir\" == \"1\" ]; then echo 'set arrow from ' $xcoord' ,0 to '$xcoord','$ycoord' head' > draw_arrow.gp fi if [ \"$dir\" == \"2\" ]; then echo 'set arrow from '$xcoord',0 to '$xcoord','$ycoord' backhead' > draw_arrow.gp fi 

Then create a simulation.gp file that looks something like this:

 count = 0; max = 5; load "simloop.gp" set yrange[0:*] plot "simulation.dat" u 1:2 wl 

Make sure the shell file has executable permissions (chmod + wrx simloop.sh), download gnuplot and enter

 load "./simulation.gp" 

This worked for me with the data file

 1 99 0 2 92.7 1 3 100.3 2 4 44.2 0 5 71.23 1 

(For testing, I got rid of time formatting. You should be able to return it without any problems.)

Then I got this graph: enter image description here

What I think is more or less what you want.

+3
source share

Although the question is quite old, here is my answer.

You can use the vectors build style, which can use arrowstyles variables based on the column value:

 set style arrow 1 backhead set style arrow 2 head set yrange[0:*] set xdata time set timefmt "%Y/%m/%d" plot "simulation.dat" using 1:2 with line,\ "" using 1:2:(0):(-$2):($3 == 0 ? 1/0 : $3) with vectors arrowstyle variable 

The value of the column is 1/0 , the point is considered undefined and is skipped.

+1
source share

All Articles