问题
Can someone elaborate in more detail on the set nonlinear
and set link
functions. The documentation is too brief on those topics. Specifically, for set link
, why is in necessary to spell out the inverse tranformation? (is it just because gnuplot does not have the capability to determine the inverse tranformation or is there any deeper reason?) What if as inverse I do provide a completely different function (not being an inverse)?
e.g. I would assume that in the following example, at least one plot would be a line but it is not, in order to produce a line, one needs to plot the third command
set xrange [0:5]
set link x2 via x**2 inverse sqrt(x)
plot x**2 axes x2y1
plot x**2 axes x1y1
plot sqrt(x) axes x2y1
This brings me back to the question, what is the purpose of the inverse in the link specification.
Now back to set nonlinear
, the documentation states: "Coordinates along the visible axis are mapped by applying g(x) to hidden axis coordinates. f(x) maps the visible axis coordinates back onto the hidden linear axis." I do not understand what the hidden axis is supposed to be and what is the linear axis. The example set nonlinear x via log10(x) inverse 10**x
makes sense to me but not in the context of the terms used in documentation (I understand the transformation but I have no idea what role the hidden axis plays here, also, there is no need for the inverse in such a transformation).
The most interesting example is the one with broken axis:
f(x) = (x <= 100) ? x : (x < 500) ? NaN : x-390
g(x) = (x <= 100) ? x : x+390
set xrange [0:1000] noextend
set nonlinear x via f(x) inverse g(x)
set xtics add (100,500)
plot sample [x=1:100] x, [x=500:1000] x
But I do not understand it at all (I understand the function definition but not in the context of the nonlinear
feature). It might be probably most useful to explain the set nonlinear
and the hidden axes nomenclature on this example.
Reaction to the answer:
Let's say first I want to plot a function f(x)
. Let v(x)
be a mapping from the linear to the visible axis: v:L->V
and l(x)
be the inverse, that is l:V->L
(L
should probably correspond to xrange
in gnuplot). From the answer I did not understand how f(x)
is calculated. If f(x): X->R
(that is a mapping from some subset of Real numbers to real numbers), where does the X
come from under those mappings. Normally (no linking or nonlinear axes) (and it holds that L=V
and v
and l
are identity maps) the Y
axis would contain numbers {y=f(x)
, such that x
is in V
}.
This becomes a little confusing in the nonlinear case, in other words do the x
come form the L
or V
space, or are the x
in y = f(x)
from the set of numbers of already tranformed X
axis which would really be f(v(x))
where x
are taken from the xrange
set in gnuplot (or space L
), or is it really f(x)
, where x
is from L
or is it f(l(x))
where x
are taken again from transformed X
axis which really is again f(l(v(x)))
x
being from the L
space or xrange
? Also, this would be a difference from the set link
which really cannot have any effect on how f(x)
is calculated.
(Interestingly enough, when plotting data the situation would probably need to be more similar to set link
since there is no function to transform.)
回答1:
1) Why is it that for set link
you need to provide an inverse function? You don't. If you just want x1 and x2 (or y1 and y1) to act identically then it is sufficient to say set link x2
or set link y2
with no forward or reverse transformation functions.
2) However if you want to link x1 and x2 via a function you need to provide both the forward and inverse functions. It may be easiest to think of these as describing the axis tic labels. If you say
set tics nomirror
set x2tics
set link x2 via x**2 inv sqrt(x)
f(x) = x
plot f(x)
You will see that for any given point along the line the x1 coordinate will read off as x and the x2 coordinate will read off as x**2. I.e. the forward function is used to calculate positions along the x2 axis. Why the inverse function? Let us suppose instead of plot x
above you instead said
plot f(x) axes x2y1
This is the same function, f(x) = x, but now it is drawn relative to the x2 axis. The inverse function sqrt(x2 coord) is used to generate the x1 axis coordinate. In other words, the function is linear along x1 but when you tell the program to plot against x2 you get a parabola. In this case you can see the numbers along both x1 and x2 so it is obvious what is going on.
This effectively defines x2 as a nonlinear axis, linked to a linear partner x1. Both the linear and nonlinear axes are visible.
3) This brings us to set nonlinear x via sqrt(x) inv x**2
, which is really the same command as before underneath the hood. We flip the directionality of the mapping so that x1 is now the nonlinear end.
Rather than linking x to coordinates along the x2 axis, it links to coordinates along a linear axis that is not drawn, the "hidden" axis. So now when we plot against x1 it we get the same effect as from plotting against x2 in the original set link
case.
回答2:
I suggest thinking about this in a different way.
Suppose you were plotting a function f(x) by hand on semilog graph paper. You look up or calculate the value of f(5) and go to mark it on the paper. Where is "5"? The paper helpfully gives you a pre-drawn series of vertical lines that you can count along until you get to the one that corresponds to "5" and then you move vertically along that line until you get to y=f(5) and place your dot. That is exactly analogous to what gnuplot does. The "via" mapping function establishes where the vertical grid lines go. Then you tell it to plot f(x_i) for some set of input values x_i. For each x_i it has to decide where on the page to draw a point. It uses the "via" function to determine the horizontal position, and the vertical position comes from f(x_i) regardless of where that horizontal position comes out.
The inverse function is needed to interpret the graph, not to draw the graph. If you place the mouse over that same plotted point f(x_i) how does it know what x value to report? It needs to take the true (visible) horizontal position v_i and back-calculate what value of x_i would have yielded via(x_i) = v_i. To do that it uses the inverse function x_i = inv(v_i) so that it can report back the mouse position in the same coordinate system as the original data.
回答3:
Can't format commands in a comment so here goes another answer box: Maybe this plot will clarify. This is plotted using version gnuplot_5.2.4
set link x2 via x**2 inv sqrt(x)
f(x)=x
plot [1:5] f(x) axes x1y1, [1:5] f(x) axes x2y1
来源:https://stackoverflow.com/questions/52120816/gnuplot-set-link-and-set-nonlinear