Reputation: 323
I have function of an electric field lines:
set isosamples 55, 55
set contour base
set cntrparam levels incremental -1.6,0.2,1.6
unset surface
splot [-4:4] [-2.2:2.2] (y*(1+1/(x**2 + y**2)))
How to put arrows on this curves, sey in position of x=2?
Upvotes: 1
Views: 485
Reputation: 13087
One way how to achieve this would be as follows:
set isosamples 200, 200
set contour base
unset surface
set cntrparam levels incremental -2,0.2,2
set xr [-4:4]
set yr [-3:3]
x_ref = 2
f(x,y) = (y*(1+1/(x**2 + y**2)))
g(x,y) = 2*x*y / ( (x*x + y*y)**2 + (x*x + y*y) - 2*y*y )
set table 'meta.levels.dat'
splot f(x, y)
set table 'meta.pnts.dat'
splot f(x_ref, y)
unset key
unset table
set terminal pngcairo enhanced size 600, 400
set output 'fig.png'
set style arrow 1 head filled size screen 0.01,30 fixed lc rgb 'dark-red'
set size ratio -1
delta = 0.01
plot \
'meta.levels.dat' w l lc rgb 'black', \
'meta.pnts.dat' every 1:1:0:0:0:0 u (x_ref-delta):($2-g(x_ref,$2)*delta):(delta):(g(x_ref,$2)*delta) with vectors as 1
The strategy is to:
f(x,y)
in the script above) and save them into a file via set table
x
(for example x_ref=2
), generate contours of f(x_ref, y)
. Since this function does not depend on x
, the generated contours will be just lines parallel with the x-
axis, thus in order to plot the points of intersection with the contours of f(x,y)
, one can take just the first point of each block (each contour) and plot it with x
-coordinate set to x_ref
.g(x,y)
)with vectors
style. Above, the delta
parameters specifies a small displacement in the x
-direction - this is in order to achieve that the only the head of the arrow is visible.In the end, the graph looks like:
Upvotes: 1