GNUplot fit with only x-errors in version 5? - gnuplot

I'm trying to fit my data using GNUplot. As it happens my data only has x-error bars. I heard version 5 is supposed to allow fitting using x errors only. How can one do this? I tried the following but as you can see I get errors that I cannot figure out:
gnuplot> fit f(x) "data1m" using 2:3:4 with xerrorbars via b,u,n
warning:
> Implied independent variable y not found in fit function.
> Assuming version 4 syntax with zerror in column 3 but no zerror keyword.
^
Need via and either parameter list or file
How can I resolve this?

It doesn't seem to work with x errors only, but you could use a very small constant y error.
Try fit f(x) "data1m" using 2:3:4:(1E-38) xyerrors via b,u,n

Related

Adding datapoints to a boxplot

R beginner here so sorry for the basic question... I have worked in class to draw some boxplots using the boxplot() function. As part of the assignment I've been asked to add data points to the boxplots. I can't seem to find an argument in the boxplot() function to do this...Is there another function I need to use? Thank you!
I recommend looking into ggplot2 package within R.
You can create multiple visualizations, including a boxplot with the data points shown. This is the ggplot code to do so:
library(ggplot2)
ggplot(df, aes(x=catvar, y=yvar)) +
geom_boxplot()+geom_dotplot(binaxis='y', stackdir='center', dotsize=1)

How to convert integer into string gnuplot

My code is the following, I would like a to assume iteratives values like '3' , '4' and so on. My code is like:
a=2
#perform some basic operation like:
b=a*2
#convert it to string
c=str(b)
p path1 u 1:($1<=0?$#c:1/0) w filledcurves y=0
The solution proposed on similar topic here so far did not work.
You should use this syntax
c=''.b
c will be equal to 'b'
gnuplot provides both sprintf (as in the C language routine) and a private implementation gprintf that offers formatting options beyond the normal ones provided by the C language. The full details with all supported format options are in the gnuplot documentation. A very simple use would be:
c = sprintf("%8.3f", b)
However, it makes no sense to convert the value to a string if your intent is to use it in a plot command that expects a number. There is no iteration in the pseudo-code you show so I can't guess exactly where you are headed with this but note that the operation #c to evaluate c as a macro expansion inside an iteration will always yield the content of c as it was prior to the iteration. So using the # operator inside an iteration is almost always wrong.
If I correctly understand your minimal incomplete non-working example, I can only guess what you probably wanted to do, i.e. limit the plot of a dataset in a certain column which is selected by some variable. Correct? If my guess is true, I would do it the following way, no need for string conversion and the use of macros. Check help column.
a=2
# perform some basic operation like:
b=a*2
plot path1 u 1:($1<=0 ? column(b) : NaN) w filledcurves y=0

Octave: Subscripts for the text function?

I'm running Octave 5.1.0. I try to reproduce the code on this page:
https://octave.sourceforge.io/octave/function/text.html
For example, I try to reproduce Demonstration 3 there, i.e. this code:
clf;
axis ([0 8 0 8]);
title (["1st title";"2nd title"]);
xlabel (["1st xlabel";"2nd xlabel"]);
ylabel (["1st ylabel";"2nd ylabel"]);
text (4, 4, {"Hello", "World"}, ...
"horizontalalignment", "center", ...
"verticalalignment", "middle");
grid on;
I get the following error message:
text(,,,,,,): subscripts must be either integers 1 to (2^63)-1 or logicals (note: variable 'text' shadows function)
I tried changing the code to:
clf;
axis ([0 8 0 8]);
title (['1st title';'2nd title']);
xlabel (['1st xlabel';'2nd xlabel']);
ylabel (['1st ylabel';'2nd ylabel']);
text (4, 4, 'Hello','horizontalalignment', 'center','verticalalignment', 'middle');
grid on;
Then I get the following error message:
text(4...[x6]...): but text has size 1x39 (note: variable 'text' shadows function)
I'm a bit stumped as to how to solve this. I also fail to reproduce other code with the text function. I started running Octave a few weeks ago, so it wouldn't be impossible that my installation failed somehow. Other functions work as expected though.
I have installed the io and statistics packages. Can they interfer somehow?
Can anybody figure out what's going on?
The key is in the error message:
note: variable 'text' shadows function
It means you have defined "text" as a variable in your workspace, and have assigned a value to it.
Therefore, now each time you try to access the text function, you are accessing your variable instead.
Clear your workspace (or just the text variable) and try again.
PS. While this is not conventional practice, I personally tend to name all my non-function variables starting with a capital letter, to avoid name-clashes with functions, since most functions in octave start with a small letter.
In general, always check that a name is not taken before you assign something to that name, to avoid 'shadowing' as in this case.

Wrong fit parameters, Undefined value during function evaluation

I'm trying to do some simple fits using Gnuplot and encountering an error which somehow I'm not able to explain. Seems that I'm doing something terribly wrong with the definition of my function.
I first started with a fit of some functions. The functional form of these is not important as the fits work pretty well, but since they are involved later I'm reporting them as well.
evap(x)=(x>x_fc)?A*qnet(x)/wm2_to_mmh:(x<x_wp)?0:(A*qnet(x)/wm2_to_mmh)*(x-x_wp)/(x_fc-x_wp)
fit evap(x) './fluxes_da_1p0.txt' using 1:2 via A, x_fc, x_wp
sensible(x)=( (qnet(x)/wm2_to_mmh)-evap(x) ) / (1+B)+C
fit sensible(x) './fluxes_da_1p0.txt' using 1:3 via B,C
Then I defined
deltasensible(x)=abs(sensible(x)-sensible(0.454))
deltalatent(x)=abs(evap(x)-evap(0.454))
period_adv=18.0
g(x)=m*deltalatent(x)*period_adv*(deltasensible(x))**e
If I impose
m=3.8
e=0.5
and just plot the function g(x) superimposed on the data it seems to work pretty well.
However if I try to fit it using the parameters
fit g(x) './advection_da_1p0.txt' using 5:2 via m,e
I get the following error
iter chisq delta/lim lambda m e
0 4.2471983038e+00 0.00e+00 5.51e+00 3.800000e+00 5.000000e-01
1 3.7149813491e+00 -1.43e+04 5.51e-01 3.573384e+00 4.843345e-01
Current data point
=========================
# = 8 out of 8
x = 0.0178156
z = 0.0309726
Current set of parameters
=========================
m = 0.0178156
e = -0.0583802
"rain_estimate.gpl", line 52: Undefined value during function evaluation
For some reason Gnuplot is trying out really strange values for m,e, although I provided their initial values. If I remove the deltalatent(x) dependency everything is working fine. Am I missing something simple?
So I think I figured it out the problem by myself. Given my data a line was the best fit for Gnuplot so that it was trying to remove the exponential dependency on deltasensible by choosing a really small coefficient. Seems more an "error" with the data than with Gnuplot itself.

Use stats inside Gnuplot inline functions

I can't figure out if it is possible to do something like
f_L0(FL)=(stats FL using ($8) name "L", \
L = L_mean, \
1)
Gnuplot keeps complaining: ')' expected and points to FL inside the function.
Any ideas how to define some function like this?
p.s. my gnuplot is 4.6 (Feb2014).
UPDATE:
since this is not possible, it seems, i would just do some analysis in Octave and output it to the file :)
No, you cannot use stats inside of inline funcitons. Gnuplot functions are very basic and can contain only 'regular' mathematical function which compute a single numerical value. You cannot get access to data files inside of functions.
The stats command is command, which is the only command besides plot and splot which has access to data files.
The use of stats is as follows: You must use it as standalone command like
stats 'filename' using 8 name "L"
after which you have access to many variables which contain results from calculations on your data (column 8 in file filename). L_mean is one of those variables, for more see show variables after having executed stats.
However, you can do many calculations inside the using statement. To subtract the mean from you data, use e.g.:
stats 'filename' using 8 name "L"
plot 'filename' using ($8-L_mean)

Resources