Gnuplot exponential function up to a certain y value - gnuplot

I am trying to plot a function f(x)=exp(-x+10) with the y-values below (and including) y=1. So basically in the range x>=10.
Trying
f(x) = x>=10 ? exp(-x+10) : 1/0
plot f(x)
does not work, because gnuplot starts plotting at y-values greater than 1. Shifting the interval a bit, I can also manage to start at values less than 1, however it seems impossible to hit exactly 1.
I presume this has something to do with precision which causes problems with the steep slope of the exponential.
Still, is there a way to properly plot that function in the specified range?

What about this? I guess you have to set a xrange including an end.
reset session
f(x) = exp(-x+10)
set xrange[10:15]
plot f(x)

Related

What the 'set logscale' does in gnuplot?

My question is more about math then the actual code.
When use the command
set logscale
on gnuplot 5.0 what is happening ?
It should represents the logarithmic values values of the x and y points.
But it doesn not seems to work properly. For example on my data I have x and y values smaller then 1 so I am expecting to see negative values for these values on the plot, but I see only postivie values.
What I am doing wrong ?
The logarithmic scale still shows the real values around the axes, just their distances are logarithmic. To really see the negative values, you need to really apply the log function:
plot "file.dat" using (log($1)):(log($2)) with lines
without setting the logscale.
A specific example might help to illustrate the effect of logarithmic scaling:
set xrange [0.1:10]
plot x**2
Let's plot this again, but this time on a logarithmic scale. Watch how the scaling of the x and y axes changes:
set logscale
replot

Gnuplot - Plot data on another abscissa by interpolation

Good evening,
I have a problem with Gnuplot. I tried to sum up my problem to make the comprehension easier.
What I have : 2 sets of data, the first one is my experimental data, about 20 points, the second one is my numerical data, about 300 points. But the two sets don't have the same abscissa.
What I want to have : I want my numerical data be interpolate on the x-experimental abscissa.
I know it is possible to do that with Xmgrace (paragraph Interpolation at http://plasma-gate.weizmann.ac.il/Xmgr/doc/trans.html#interp) but with Gnuplot ?
What I want to have in addition : is it possible, then, to subtract the y-experimental data of my y-numerical data at the x-experimental abscissa points ?
Thank you in advance for your answer,
zackalucard
You cannot interpolate the ordinate values of one set to the abscissa values of the other. gnuplot has no mechanism for that.
You can however plot both datasets using one of the smoothing algorithms (check "help smooth") with common abscissa values (which might (be made to) coincide with the original values of one set.)
set table "data1.tmp"
plot dataf1 smooth cspline
set xrange [GPVAL_x_min:GPVAL_X_max] # fix xrange settings
set table "data2.tmp"
plot dataf2 smooth cspline
unset table
Now you have the interpolated data in two temporary files, and only need to combine them into one:
system("paste data1.tmp data2.tmp > correlation.dat") # unixoid "paste" command
plot "correlation.dat" using 2:4
(If you have a sensible fit function for both datasets, the whole thing becomes much easier : plot dataf1 using (fit1($1)):(fit2($1)))
You can use smoothing, this should do the trick
plot "DATA" smooth csplines
(csplines is just one options, there others, e.g. bezier)
But I don't think you can automatically determine the intersection of the smoothed curved. You use the mouse to determine the intersection visually, or alternatively fit some functions f(x) and g(x) to your curves and solve f(x)=g(x) analytically

Inversed logarithmic scale in gnuplot

When plotting data which are very dense in small ranges of y, the logarithmic scale of gnuplot is the right scale to use.
But what scale to use when the opposite is the case? let's say most y values of different curves are between 90 and 100. In this case I want to use something like a inversed logarithmic scale. I tried a log scale between 0 and 1 but gnuplot wants me to choose a scale greater than 1
How can I achieve this?
You are right, you can use the inverse of the logarithmic function, which is the exponential. But gnuplot only supports logarithmic scales, so you have to do the conversion on your own:
plot "myData" using 1:(exp($2))
You will also have to handle the axis tics on your own. Either you just set them via a list like
set ytics ("0" 1.00, "1" 2.72, "2" 7.39, "3" 20.09, "4" 54.60, "5" 148.41)
or you use the link feature for axes of gnuplot 5. The following code uses the y2axis (right y-axis) to plot the data and calculates the tics on the left y-axis from the right one.
set link y via log(x) inverse exp(x)
plot "myData" using 1:(exp($2)) axes x1y2
Side note: Always remember that a non-linear axis is hard to understand. Logarithmic scales are common, but everything else not. So, be careful when presenting the data

xrange limiting in logscale plot in gnuplot

I am trying to fit a plot in gnuplot using logscale. I have 50000 data points.
At first I fit plot in this way.
f(x) = b + m*x
fit f(x) "xyMSD-all-mal-cel-iso-bcm-thermo2.dat" using 1:2 via m,b
I got slope value. Then I tried to get slope value at different range as below.
fit [30000:50000] f(x) "xyMSD-all-mal-cel-iso-bcm-thermo2.dat" using 1:2 via m,b
The above code works fine. In next attempt I tried,
f(x) = b + m*x
fit f(x) "xyMSD-all-mal-cel-iso-bcm-thermo2.dat" using (log($1)):(log($2)) via m,b
Above works fine too. I get the slope value. Then I tried to choose the xrange like below. This is where I have problem. It does not work.
fit [500:5000] f(x) "xyMSD-all-mal-cel-iso-bcm-thermo2.dat" using (log($1)):(log($2)) via m,b
Is there any way to achieve this?
Appreciate any help
The range has to fit the expression, which in your case are log values. So make sure the log values are within range. For example, if your range for ($1):($2) is [500:5000], then the corresponding range for (log($1)):(log($2)) should be something like [2.69:3.69].
Gnuplot first uses the expression on your data. Limiting the range is the second step, so in this case the logarithm of the required data points have to be in the xrange.
AND don't forget: logscale uses the logarithm based on 10 but log(x) or log($1) means logaritm based on 'e' (approx. 2.7183). To be harmonic with the logscale use function log10(x) (or log(x)/log(10)).
PS: I know that the original question had been answered previously, but I haven't got enough prestige to append my useful comment about the log() function as a comment.

custom y scale in plot for

I have a data file, looking like
550 1.436e+00 7.857e-01 5.906e-01 4.994e-01 4.574e-01 4.368e-01 4.260e-01 4.273e-01 4.296e-01 4.406e-01 4.507e-01 4.639e-01 4.821e-01 5.008e-01 5.156e-01 5.378e-01 5.589e-01 5.768e-01 5.970e-01 6.196e-01 6.422e-01 6.642e-01
The first column is for x-axis, the rest ones are for the y-axis, 22 curves totally.
I want to plot the data so that y tics represent cube roots of the values. Actually, I want my cubic curves to become linear, to show, that they're cubic in the normal coordinates (and it is fixed by my task to use these coordinates).
I tried to use the following command:
plot for [i=2:23] datafile using 1:(i ** .333) smooth cspline
It expects column number in place of i.
I know, the following is correct:
plot datafile using 1:($2 ** .333) smooth cspline
giving me the desired plot for my first line. But how do I modify this for plot for?
If you want the column number in place of i, you should use column(i) in the using specification.
plot for [i=2:23] datafile using 1:(column(i) ** .333) smooth cspline

Resources