I have data:
0 315
0.159 284
0.321 246
0.47 202
0.631 164
0.786 136
0.958 102
1.104 74
1.307 42
1.461 17
1.524 10.9
1.6 4. 6
1.728 0
I have a code :
set xlabel "Zaporna napetost [V]"
set ylabel "Tok [pA]"
set yrange [-25:350]
set xrange [-0.1:1.8]
set xtics 0.3
set mytics 2
set mxtics 2
f(x)=k*x**2+n
fit f(x) 'D:\Petra\sola\praktikum\fotoefekt\365.txt' using 1:2 via k,n
plot 'D:\Petra\sola\praktikum\fotoefekt\365.txt' using 1:2 lc rgb 'black' t"UV" , \
f(x) lc rgb 'black' t""
And the fit i get is totaly of. Can anyone help.
Looks like you have experimental data. As you stated in your comments, you expect the have a linear dependency. You cannot change your physics and change the fitting function, just because it might look better.
In your case you could e.g. skip the points above 1.4, if you have a good reason (e.g. systematic errors), but use a linear fit:
f(x) = a*x + b
fit [0:1.4] f(x) '365.txt' via a,b
plot '365.txt' title 'experimental data', f(x) title sprintf('fit with %.2f·x + %.2f', a, b)
Related
I have plotted a graph (X-top axis, Y-bottom axis) with fsteps function in Gnuplot. Next, I tried to add an error bar as a shaded region(transparent) to the graph, but unable to plot it on the graph. Below is the code so far I have tried and also attached the graph.
#!/usr/bin/gnuplot
reset
set border lw 30
set term pngcairo size 10000,10000 font "arial-Bold,130"
set output 'out.png'
unset key
set size ratio 1.2
set style data lines
set xtics format ""
set x2tics nomirror
set ytics out nomirror
set ytics 0,20
set x2label "Vs (km/s)" offset -1.0
set ylabel 'Depth (km)' offset 1.5
set xrange [2.5:4.8]
set yrange [314:0]
set label 3 at 2,120
set key samplen 1.7 at 3.0,135
#
set label 1 '(a)' font "arial-Bold,130" at 0.8,15 right
set label 3 "C3 (MNAI)" center font "arial-Bold,130"
set style fill transparent solid 0.25
set style fill noborder
plot 'MAN.inmd' lc rgb 'blue' lw 35 title "Initial model" with fsteps,\
'MAN.outmd' using 1:2 lc rgb 'red' lw 35 dt"-" title "Inverted model" with fsteps ,\
'MAN.outmd' using 1:($2-$3):($2+$3) with filledcurve lc "blue" notitle,
Example Data for file MAN.outmd X Y Z(Error)
0 3 0
0.4475 3.1 0
0.4475 3.5 0
2.6738 3.6 0.0552
2.6738 5 0.0552
3.8441 5.1 0.0592
3.8441 8 0.0592
3.6302 8.1 0.0395
3.6302 15.935 0.0395
4.5176 15.1 0.041
4.5176 113.296 0.041
4.2443 113.3 0.1024
4.2443 214 0.1024
4.4584 214.1 0.1077
4.4584 314 0.1077
I want output should be as given below (example)
gnuplot can easily fill the area between two "horizontal" curves (i.e. unique x-values), but as far as I know, not between two vertical curves. However, gnuplot can fill some enclosed areas. So, the workaround is to create datapoints which surround the area to be shaded. For this, you "plot" the data into a datablock, once "forward" with x-dx and once "backwards" with x+dx. This can be done easiest if you have the data already in a datablock, because then you can easily loop the data forward and backwards. In case you have your data in a file, see here: gnuplot: load datafile 1:1 into datablock
Code:
### fill between vertical curves
reset session
$Data <<EOD
0 3 0
0.4475 3.1 0
0.4475 3.5 0
2.6738 3.6 0.0552
2.6738 5 0.0552
3.8441 5.1 0.0592
3.8441 8 0.0592
3.6302 8.1 0.0395
3.6302 15.935 0.0395
4.5176 15.1 0.041
4.5176 113.296 0.041
4.2443 113.3 0.1024
4.2443 214 0.1024
4.4584 214.1 0.1077
4.4584 314 0.1077
EOD
# create datablock with circumference of shaded area
set print $XErrorFill
do for [i=1:|$Data|] {
print real(word($Data[i],1))-real(word($Data[i],3)), real(word($Data[i],2))
}
do for [i=|$Data|:1:-1] {
print real(word($Data[i],1))+real(word($Data[i],3)), real(word($Data[i],2))
}
set print
set yrange [:] reverse
set style fill noborder
plot $XErrorFill u 1:2 w filledcurves lc "light-grey" notitle, \
$Data u 1:2 w l lw 1.5 lc rgb "red" notitle
### end of code
Result:
I'm using Gnuplot with the 2,2 multiplot environment.
One of my datasets looks like this:
# Avg1. Min1. Max1. Avg2. Min2. Max2.
25 0.049 0.002 0.108 0.051 0.004 0.102
50 0.034 0.005 0.070 0.036 0.004 0.086
100 0.028 0.012 0.044 0.026 0.012 0.054
And I'm using the following script to plot the first graph (I think once I get the first one right I can just repeat the code):
#!/usr/bin/env gnuplot
set term post eps color solid enh
set multiplot layout 2,2 rowsfirst
set grid ytics
set offsets 0.5, 0.5
unset key
set ylabel offset 1,0
set xtics ("25" 1, "50" 2, "100" 3)
### First plot
set tmargin at screen 0.95
set bmargin at screen 0.65
set lmargin at screen 0.10
set rmargin at screen 0.45
set ylabel 'Y-Label Here'
plot 'data.dat' u :2:3:4 w yerrorlines ti 'Title1', \
'' u :5:6:7 w yerrorlines ti 'Title2'
### three other graphs
unset multiplot
And I have three more plots like this. The problem is that my X-axis only shows 25 and 50 (shown below).
I don't know how to fix this. Can anyone help please?
I've tried using 1:2:3:4 instead, but it shows the intermediate X-tics, which I don't want to show.
PlotExample
If you don't specify an explicit column for the x-value, then gnuplot uses the row index, which starts at zero:
set xtics ("25" 0, "50" 1, "100" 2)
plot 'data.dat' u 0:2:3:4 w yerrorlines ti 'Title1'
You can also directly use the values in the first column as xticlabels:
plot 'data.dat' u :2:3:4:xtic(1) w yerrorlines ti 'Title1'
Given dataset:
0 t1 0.52
1 t2 0.66
2 t3 0.58
3 t4 0.57
4 t5 0.68
5 t6 0.61
6 t7 0.55
7 t8 0.52
8 t9 0.58
9 t10 0.50
10 t11 0.59
I cannot manage to get the colors of the bars to change. What I'm trying below is to color green the highest score which happens on line 4. Please have a look over the below:
set terminal postscript eps enhanced 20
set output "edscore2_joint.eps"
set style line 1 lc rgb "#5F9EA0"
set style line 2 lc rgb "#DC143C"
set style line 3 lc rgb "green"
set yrange [0:1]
set ylabel "ed_{score}"
set xlabel "Technique"
set style fill solid
set boxwidth 0.5
set xtics rotate by -45
plot "edscore2_joint.dat" using 1:3:xtic(2) with boxes ls 1 fillstyle pattern 1 notitle ,\
"edscore2_joint.dat" every ::4::4 using 1:3:xtic(2) with boxes ls 3 fillstyle pattern 2 notitle ,\
"edscore2_joint.dat" using 1:($3+0.05):3 with labels notitle
The terminal postscript is monochrome by default. Use either the option color, or, if you have a recent enough gnuplot version, use the terminal epscairo.
I am trying to plot some data with Gnuplot and would like to use a logscale on the x axis. This does not work, Gnuplot gives the error "x range must be greater than 0 for log scale". I saw examples that used a logscale with negative values on the y axis and tried to do it similar for the x axis, but it seems I can not get it to work. Initially I thought it would be the zero values, but even when I remove them, it does not work.
This is a little example:
stats 'stat_data1'
num1=STATS_records
stats 'stat_data2'
num2=STATS_records
set terminal pdf
set output "Cumulative_noise.pdf"
set autoscale yfix
set autoscale xfix
set key bottom right
set xlabel 'Noise in dB'
set ylabel 'Percent'
set xrange [0:110] reverse
set logscale x
set style increment user
set style line 2 lc rgb '#FF0000' lt 1 pt 1 ps 1
set style line 3 lc rgb '#008000' lt 2 pt 2 ps 2
set style line 4 lc rgb '#0000FF' lt 3 pt 3 ps 3
plot 0/0 notitle,\
'stat_data1' u (-$3) : ((100.0/num1)) title 'Node 1' smooth cumulative,\
'stat_data2' u (-$3) : ((100.0/num2)) title 'Node 2' smooth cumulative
And here some data. First file:
1437818411 -54 -95 85.2 0.0
1437818425 -54 -95 78.0 0.0
1437818440 -71 -95 38.7 0.0
1437818456 -70 -95 51.7 0.0
1437818471 -71 -95 42.0 0.0
Second file:
1437818545 -50 -95 43.7 100.0
1437818561 -51 -95 52.0 100.0
1437818576 -50 -94 79.4 0.10744142234781584
1437818592 -51 -94 16.6 0.308927509416507
1437818605 -49 -95 85.2 0.04368438558438699
I hope somebody has an idea as this would be very convenient. Thank you in advance!
The numbers given in the xrange settings are also subject to the actual axis transformations.
Removing the set xrange [0:110] fixes the error.
I have a dataset of 818,741 samples. values range between 0 and 7276. I am using the following gnuplot script to plot the data.
#+begin_src gnuplot :var data=xtics :exports code :file file.png
reset
set term png
set output "data.png"
set title "Variations/entity"
set xlabel "entity"
set xtics rotate by -45
set yrange [0:7276]
set ylabel "# fo variations"
plot 'sort_1.txt' u 2:xticlabels(1) w lp lw 2 notitle
#+end_src
Problem
The problem is that the cruve becomes a straight line when I use the dataset with the 818,741 samples.I cannot see the distribution of the data anymore. What plot do you suggest.
Sample data
entity # of variations
E0669803 7276
E0726485 496
E0679687 459
E0159288 395
E0018102 337
E0498282 333
E0349508 322
E0566375 315
E0096588 314
E0182788 313
E0595006 312
E0550909 291
E0338738 290
E0031352 290
E0409686 284
E0576457 279
E0277375 275
E0277379 0
update
The following script is for the whole dataset. Well I don't think I can do any better.
#+begin_src gnuplot :var data=xtics :exports code :file file.png
reset
set term png
set output "data.png"
set title "Variations/entity"
set xlabel "entity"
set xtics rotate by -90
set yrange [0:7276]
set ylabel "# fo variations"
plot 'data.txt' u 2:xticlabels(1) every 100000 w lp lw 2 notitle
#+end_src
If you want to extract statistical data from your data sample, try boxplots, one for each entity:
set yrange [0:7276]
set style fill solid 0.25 border -1
set style boxplot nooutliers pointtype 7 separation 2
set boxwidth 1
plot "data.txt" using (1.0):2:(0):1 with boxplot notitle
This creates one boxplot for all data samples with the same string value in the first column, your "entity". And one boxplot for each unique entity is generated.