Reputation: 22128
I have a Gaussian curve drawn via gnuplot and I want to have a line which goes up from the x-axis, stops exactly where it hits the curve, and goes perpendicular to the left to hit the y-axis, ideally displaying the values at both axis, and displaying a symbol where it intersects with the x-axis.
What is the right way to add this in gnuplot? I tried to play around with arrows using nohead but I am a newbie to gnuplot and can't seem to find a way to achieve what I need.
Upvotes: 11
Views: 40748
Reputation: 22128
I managed to find a simple solution to my needs. The arrow
can actually be used with nohead
by specifying the y
coordinates of the to
to be the function of the plot itself.
So lets say we have a function f(x), and we want to draw a line from x=3 to f(3) and the corresponding horizontal line y= f(3), all we have to do is add 2 arrows:
set arrow from 3,0 to 3,f(3) nohead
set arrow from 0,f(3) to 3,f(3) nohead
Since I also wanted tics to be added where the line intersects with the axis, if they're missing, one could then do:
set xtics add (3 3)
set ytics (f(3) f(3))
Since there might be decimal places involved on the y
axis one might also need to do something like this (in this case it has 3 decimal places):
set format y "%1.3f"
I didn't manage to find a way to do a label underneath a tic on the x-axis, but the above sufficed for my needs. Hope it helps for someone else looking for the same solution.
Upvotes: 18
Reputation:
I have solved this issue in the past in the following way:
Knowing the pair (x,y) of the point on the curve where you want your lines to go to, do: - calculate a set of values (x,{0..y}), and plot it. This would be the vertical line - - calculate a set of values ({0..x},y), and plot it. This would be the horizontal line
Alternatively, you can create dummy arrays a (x,{whole y range}) and ({whole x range},y), and plot these from your origin to the point (x,y) by specifying the (x,y) point in the range setting.
May be these are not the most efficient ways, but both worked for me. I did these manipulations in Perl Data Language (PDL), using a Perl script, from which I write a gnuplot configuration file and call gnuplot using "system".
Hope this helps!
Upvotes: 1