2
votes

I want to do exactly this: https://tex.stackexchange.com/questions/165360/pgfplots-and-gnuplot-how-to-add-asymptote-a-xtick-that-isnt-a-number-and-can/165366#165366?newreg=53a345ba2c3f4f4fbf210af7872b1168 but in gnuplot (without the latex stuff). How can I do that?

This is my plt-file:

reset
set xlabel "Distance [kpc]"
set ylabel "Velocity [km/s]"
unset key
set grid
f(x)=m*x+b
set xrange [0:10]
set yrange [10:]
set xtics
set xtics nomirror
set ytics nomirror
set logscale y
fit f(x) "vd.dat" u 1:2 via m, b
plot f(x) lw 2 lc rgb"black"
set term png
set output "~/uni/J2017+0603/J2017+0603_sim_pm_modified.png"
show output
plot f(x) lw 2 lc rgb"black"

this is the output: plot http://www.ifirn.de/inh/J2017+0603_sim_pm_modified.png

And I want to know, for example, which distance belongs to 87km/s. And I wnat gnuplot to draw a horizontal line from 87km/s to graph, then vertical down to the x-axis and display the result.

1

1 Answers

2
votes

The procedure is the same as described in the link you give: Find the inverse of the function and add the result.

The inverse of your function is (f(x)-b)/m. To display the result, use set arrow, with the graph coordinate system to hit the axes, and first to get the coordinates of the actual intersection.

To add the results on the axes, use set xtics add and set ytics add.

An example script (without the fitting part):

reset
set xlabel "Distance (kpc)"
set ylabel "Velocity (km/s)"
set grid

m = 234; b = 1
f(x)=m*x+b
set xrange [0:10]
set yrange [10:]
set tics nomirror
set logscale y

set samples 1000
y = 2000.0

set arrow from graph 0, first y to first (y-b)/m,y nohead lt 3
set arrow from first (y-b)/m, y to first (y-b)/m, graph 0 nohead lt 3
set ytics add (sprintf("%.f", y) y)
set xtics add (sprintf("%.2f", (y-b)/m) (y-b)/m)
plot f(x) lw 2 lc rgb"black"

enter image description here