R.U.
R.U.

Reputation: 353

How to get a middle-headed arrow in gnuplot?

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

Upvotes: 3

Views: 2176

Answers (2)

Christoph
Christoph

Reputation: 48390

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

Upvotes: 6

andyras
andyras

Reputation: 15910

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

----> + ----- = ---->-----

Upvotes: 0

Related Questions