3

I want to draw an arrow in gnuplot with the arrow head appearing in the middle of the arrow instead of either extremes. Tried middlehead option but doesn't seem to work.

Here is the script that I am using to create the image below,

set style arrow 1 front head filled size screen 0.008,6 lt 1 lw 1
set arrow from  0.4750,-0.3592 to 1.05767,0.4179 as 1

enter image description here

R.U.
  • 355
  • 1
  • 5
  • 12

2 Answers2

6

As andyras already pointed out: there is no option to get this. However, you can create a function which builds the two arrows for you and does the calculation of the intermediate point. The function middlearrow builds together a string containing both arrow definitions, which must then be processed with eval:

set style arrow 1 front head filled size screen 0.03,15 lt 1 lw 1
middlearrow(from_x, from_y, to_x, to_y) = \
        sprintf('set arrow from %f,%f to %f,%f as 1 nohead;', 0.5*(from_x + to_x), 0.5*(from_y + to_y), to_x, to_y).\
        sprintf('set arrow from %f,%f to %f,%f as 1', from_x, from_y, 0.5*(from_x + to_x), 0.5*(from_y + to_y)) 

eval(middlearrow(0.1,0.1,0.9,0.9))

set xrange [0:1]
set yrange [0:1]

plot 0

Result with 4.6.4:

enter image description here

Christoph
  • 47,569
  • 8
  • 87
  • 187
  • Many thanks. It works for me. However I needed to tweak the function a little bit as the arrowhead wasn't appearing exactly in the middle. – R.U. May 14 '14 at 08:11
  • Right, the arrow tip is in the center. If you need some flexibility, you could change the function signature to `middlearrow(from_x, from_y, to_x, to_y, r) = ...`, which `r` being the fraction where the arrow tip is placed. – Christoph May 14 '14 at 08:15
0

Draw two arrows, one with a head and one without.

----> + ----- = ---->-----
andyras
  • 15,542
  • 6
  • 55
  • 77
  • 1
    Although this improvisation works however makes it quite tedious. I am calculating tangent points at different curves then need to connect them with arrows to show transitions. One example is shown in the image. To draw two arrows I would need to calculate a third point between the two points. Hence every time the gradient of the arrow line changes I would need to find a new point so on and so forth. Thanks anyway. – R.U. May 13 '14 at 09:17