0
votes

I print force fields for various functions and x and y ranges like for f in the following almost minimal example:

f(x,y) = -x*y

unset key
set xrange [-2:2]
set yrange [-1:1]
set samples 40
set isosamples 20

delta = 2.0 / 41
ds(x,y) = sqrt(1.0+f(x,y)**2)

plot "++" using ($1):($2):(delta/ds($1,$2)):(delta*f($1,$2)/ds($1,$2)) with vectors

How can I use in the calculation of delta the current values of internal settings such as samples and isosamples and x and y ranges in order to adapt the lengths of the little arrows to their mutual distances so that arrows are well visible but do not overlap?

Background is that I want to split the above code into two files, the first to define f and the range and sample settings and then load the rest. The rest than can be re-used to plot force fields for many functions.

It would be possible to circumvent the read-access to gnuplot settings by defining variables and then set xrange and yrange etc. according to these. I would, however, prefer to use the gnuplot built-in set command if this is possible.

I know that there are variables GPVAL_X_MIN, GPVAL_X_MAX, GPVAL_Y_MIN and GPVAL_Y_MAX after the first time, plot is invoked. It would be preferable not to require a plot and only read the setting from the preceding set xrange and set yrange.

And is there any gnuplot-defined variable for samples and isosamples? Is there anything like GPVAL_SAMPLES and GPVAL_ISOSAMPLES?

1
No, these variables don't exist, but you can define them yourself: SAMPLES=20; set samples SAMPLES... BTW, with show variables GPVAL you can see all variables starting with "GPVAL" - Christoph

1 Answers

0
votes

as a dirty solution, you could generate an auxiliary empty plot in order to initialize those variables:

set terminal pngcairo enhanced
set output 'fig.png'

set xr [-2:2]
set yr [-4:4]

set multiplot
plot 1/0 t ''

print GPVAL_X_MIN, GPVAL_X_MAX

plot sin(x) w l

However, it seems much more consistent to use the approach suggested by @Christoph in the comments, i.e., declare a custom variable and use it in the definition of the ranges and other settings...