"with labels" in splot causes gnuplot crash - gnuplot

Well, not really crash, but a kind of infinite loop: gnuplot doesn't react.
I' m trying to have a contour plot from a datafile, with labels on each contour line. Here's my gnuplot code:
set key at screen 1, 0.9, 0 right top vertical Right noreverse enhanced autotitle nobox
set view map
unset surface
set isosamples 50, 50
set contour base
set cntrparam bspline
set cntrparam order 8
set cntrparam levels discrete -25,-50,-100,-150,-300,-500
set style data lines
set title "plot"
set xlabel "Temps (ns)"
set xrange [ * : * ] noreverse nowriteback
set ylabel "T_e"
set yrange [ * : * ] noreverse nowriteback
splot "Hydro-fct-temps.csv" u 1:3:6 lw 2
This code works fine, but if I replace the splot line with (as I've seen in http://gnuplot.sourceforge.net/demo_5.0/contours.html):
splot "Hydro-fct-temps.csv" u 1:3:6 lw 2, "Hydro-fct-temps.csv" u 1:3:6 with labels boxed
then gnuplot doesn't plot anything, and I only can get the prompt with a ctrl-c. The data file is something like :
#Time [ns] N_e [1/cc] T_e [eV] Z Rho [gr/cc] Pos [um]
0.000000e+00 0.000000e+00 0.000000e+00 4.100000e+01 8.500000e+00 0.000000e+00
0.000000e+00 0.000000e+00 0.000000e+00 4.100000e+01 8.500000e+00 4.579648e-03
0.000000e+00 0.000000e+00 0.000000e+00 4.100000e+01 8.500000e+00 9.191354e-03
0.000000e+00 0.000000e+00 0.000000e+00 4.100000e+01 8.500000e+00 1.383534e-02
Any idea to help me? Thanks!
Edit: I'm on Mac OS 10.11.4, using Gnuplot 5.0.3, aqua terminal

Related

Plot a error bar as shaded region in GNUPLOT

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:

Gnuplot yerrorlines xtics issue

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'

Plot angle arches, or how to have a custom `range` for successive (re)plot

I'm trying to create a 3d plot of some vectors in a unit sphere with angle arches between some of them.
Here is the current situation. Note: I currently tried only two angle arches but in the end I need some more.
In order to add the arches, I oriented myself on the following tutorial (near the end '3D Case'): http://www.gnuplotting.org/tag/circle/
The problem is, they use urange and vrange to limit the angle of the arch. They can do this, because they only have two angles in the example and not multiple as I have.
So with my limited mathematical and gnuplot knowledge, I tinkered something together which kind of works:
my angle arches attempt
What is kind of ungly is, that the line from the 'end' of my angle arch to 0,0,0is drawn and that even on top of my arrows specified underneath.
Is there a way to plot every arch with different urangeand vrange? Something like:
splot cos(u)*cos(v),cos(u)*sin(v),sin(u) notitle lc rgb "#B0000000" linetype 2,\
[-pi/2:pi/2][0:2*pi] fvx(v),fvy(v),fvz lc rgb "#7878ff" linetype 1,\
[-pi/2:0][0:2*pi] fux(u),fuy(u),fuz(u)
Or is there something I'm completely missing?
Here is my code so far..:
set xrange [-1:1]
set yrange [-1:1]
set zrange [-1:1]
set xyplane at 0 #z axis 0 should be on xy-plane
set parametric
set urange [-pi/2:pi/2]
set vrange [0:2*pi]
set key off
#view schraeg: 32,320
set view 32,320, 1,1
set style arrow 1 linecolor rgb "#FF0000"
set style arrow 2 linecolor rgb "#ff5252"
set style arrow 3 linecolor rgb "#0000FF"
set style arrow 4 linecolor rgb "#0000FF" nohead
set style arrow 6 linecolor rgb "#880000FF" nohead
set style arrow 5 linecolor rgb "#FF0000" nohead
# Angle between m' and x axis
r0 = 0.1
fvx(v) = v<2.5793017540894563 ? r0*cos(v) : 0
fvy(v) = v<2.5793017540894563 ? r0*sin(v) : 0
fvz = 0
# Angle between n and m
r = 0.5
fux(u) = u >= 0.7915660086835659 ? r*cos(u)*cos(2.5793017540894563) : 0
fuy(u) = u >= 0.7915660086835659 ? r*cos(u)*sin(2.5793017540894563) : 0
fuz(u) = u >= 0.7915660086835659 ? r*sin(u) : 0
splot cos(u)*cos(v),cos(u)*sin(v),sin(u) notitle lc rgb "#B0000000" linetype 2,\
fvx(v),fvy(v),fvz lc rgb "#7878ff" linetype 1,\
fux(u),fuy(u),fuz(u)
set arrow from 0,0,0 to 1,0,0 nohead # x axis
set arrow from 0,0,0 to 0,1.5,0 nohead # y axis
set arrow from 0,0,0 to 0,0,2 nohead # z axis
set arrow from 0,0,0 to 0.49999999999999994, 0, 0.8660254037844387 arrowstyle 1 #light
set arrow from 0,0,0 to 0.49999999999999994, 0, 0 arrowstyle 5 #light 1
set arrow from 0.49999999999999994, 0, 0 to 0.49999999999999994, 0, 0.8660254037844387 arrowstyle 5 #light 2
set arrow from 0,0,0 to -0.49999999999999994, 0, 0.8660254037844387 arrowstyle 2 #specular
set arrow from 0,0,0 to -0.6078313957973345, 0.3830222215594889, 0.6955824696430309 arrowstyle 3 #measure
set arrow from 0,0,0 to -0.6078313957973345, 0.3830222215594889, 0 arrowstyle 6 #measure flat
set arrow from 0,0.3830222215594889,0 to -0.6078313957973345, 0.3830222215594889, 0 arrowstyle 6 #measure 1
set arrow from -0.6078313957973345,0,0 to -0.6078313957973345, 0.3830222215594889, 0 arrowstyle 6 #measure 2
set arrow from -0.6078313957973345, 0.3830222215594889, 0 to -0.6078313957973345, 0.3830222215594889, 0.6955824696430309 arrowstyle 4 #measure 3
pause -1
If you cannot specify the range (because you are using a replot approach, which is sensible), then, change the function!
You can make a change of variable to accomodate any other range. Say:
set parametric
set urange [0:pi]
splot 0,0,0 # because internal variables are not initialised else, this will not be a problem in your example.
CoV(u,min,max)=min+(u-GPVAL_U_MIN)*(max-min)/(GPVAL_U_MAX-GPVAL_U_MIN)
splot cos(CoV(u,pi/3,pi/2)),sin(CoV(u,pi/3,pi/2)),0
The CoV (change of variable) uses the ranges of variable u at the time of plotting (Gnuplot variables GPVAL_U_*) to rescale u between the prescribed minimum and maximum values. The ugly splot 0,0,0 might be spared with future versions of gnuplot using stats command, but not yet with version 5.0. Alternatively, one can set his own variables initially:
my_u_min=0.
my_u_max=pi
set urange [my_u_min:my_u_max]
U_MIN(dummy)=(exists("GPVAL_U_MIN")?GPVAL_U_MIN:my_u_min)
U_MAX(dummy)=(exists("GPVAL_U_MAX")?GPVAL_U_MAX:my_u_max)
CoV(u,min,max)=min+(u-U_MIN(0))*(max-min)/(U_MAX(0)-U_MIN(0))

values at x-axis fall in between xtics

I am trying to plot a graph where the x-values fall in between xtics.
For example, I want my xtics to be
C72 C73 C74 C75 C76 C77 C78 C79 C80 C81
and the points fall in between C72 C73 ; C73 C74 ; C74 C75 ; and so on.
My data points are
> 2.5 0.17509 C72
> 3.5 0.220434 C73
> 4.5 0.164918 C74
> 5.5 0.172477 C75
> 6.5 0.156145 C76
> 7.5 0.171699 C77
> 8.5 0.165199 C78
> 9.5 0.191207 C79
> 10.5 0.211656 C80
> 11.5 0.202233 C81
I used xticlabels() in the script definitions as below:
#OUTPUT
set terminal pngcairo size 650,450 enhanced dash
set output "xplot_gauche_malto-thermo.png"
set style line 4 lt 4 lw 10 # Please DISABLE pause -1
#MICRO
set macro
labelFONT="font 'arial,22'"
scaleFONT="font 'arial,18'"
scaleFONT2="font 'arial,18'"
keyFONT="font 'arial,18'"
# AXIS DEFINITIONS
set xrange [0:12]
set yrange [0:0.8]
set xtic (2,3,4,5,6,7,8,9,10,11) #scaleFONT2
set ytic #scaleFONT
set boxwidth 0.8
set size square
#PLOT
plot "all_dihedrals_in_layers_malto.dat" using 1:2:xticlabels(3) with linespoints lw 2 linecolor rgb "black" pointtype 1 pointsize 2 title ""
If I use the code as above, to get a plot using only column 1 and 2 from data file (as given above) I get the points fall in between 2-3, 3-4, 4-5 and so on.
Unfortunately if I use "xticlabels()", I don't get the graph as I wanted where the point supposed to fall in between C72-C73, C73-C74, C74-C75 and so on.
Appreciate in advance for any help.
Thanks
try something like this.. (Untested i dont have gnuplot on this machine..)
plot "all_dihedrals_in_layers_malto.dat" using 1:2 with linespoints \
lw 2 linecolor rgb "black" pointtype 1 pointsize 2 title "" ,\
"all_dihedrals_in_layers_malto.dat" using ($1-.5):0/0:xticlabels(3)
of course you could alternately manually key in the labels on the set xtics line..
Edit..had a chance toi try it, the 0/0 or (0/0) does not work. What you need to do is plot some value out of range.. eg:
set yrange [0:]
plot "all_dihedrals_in_layers_malto.dat" using 1:2 with linespoints \
lw 2 linecolor rgb "black" pointtype 1 pointsize 2 title "" ,\
"all_dihedrals_in_layers_malto.dat" using ($1-.5):-1:xticlabels(3) notitle

Gnuplot error bars values below 1 doesn't appear

I have those data:
Length A B C D E F A_err B_err C_err D_err E_err F_err
17 0,51 1,4 0 0 0 0,07 0,11 0,33 0 0 0 0,08
18 1,33 2,49 1,88 0,51 1,21 0,2 0,18 0,43 1,05 0,5 0,5 0,14
19 2,56 3,83 3,75 0,76 4,22 0,81 0,25 0,53 1,47 0,61 0,92 0,28
20 8,28 7,22 3,44 5,46 5,16 9,19 0,44 0,72 1,41 1,59 1,02 0,89
21 29,96 20 15,78 16,65 13,66 62,58 0,74 1,11 2,82 2,6 1,58 1,49
22 34,16 42,3 56,25 31,51 37,14 16 0,76 1,37 3,84 3,25 2,22 1,13
23 14,23 16,59 17,03 29,86 21,28 1,55 0,56 1,03 2,91 3,2 1,88 0,38
24 6,98 4,39 1,72 12,58 9,6 9,54 0,41 0,57 1,01 2,32 1,35 0,9
25 1,23 1,02 0,16 1,65 4,55 0,05 0,18 0,28 0,31 0,89 0,96 0,07
26 0,45 0,44 0 0,89 1,76 0 0,11 0,18 0 0,66 0,6 0
27 0,18 0,1 0 0 1,04 0 0,07 0,09 0 0 0,47 0
With this code, I obtain a nice histogram with error bars:
set terminal pngcairo enhanced font "arial,15" fontscale 2.0 size 1600,900
set output 'length.png'
set style fill solid 0.7 border lt -1
set key inside right top vertical Right noreverse noenhanced autotitles columnhead nobox
set grid ytics
set nokey
set style histogram errorbars linewidth 1 gap 3 title offset character 0, 0, 0
set datafile missing '-'
set style data histograms
set xtics border in scale 1,0.5 nomirror offset character 0, 0, 0 autojustify
set xtics norangelimit font ",12"
set xtics ()
set xlabel "n"
set ylabel "Percentage (%)"
set title "length"
set bars 0.3 front
set datafile separator "\t"
set yrange [ 0 : * ] noreverse nowriteback
plot 'length.dat' using 2:8:xtic(1), '' u 3:9:xtic(1), '' u 4:10:xtic(1), '' u 5:11:xtic(1), '' u 6:12:xtic(1), '' u 7:13:xtic(1)
The obtained image is here: http://i.stack.imgur.com/s88QJ.png
But, some error bars just not appear. I notice that is because the error value is below 1. But why ? I'd like all error bars appearing. Is there a problem in the code that forbid errors below 1 to appear ?
Thanks for your help
To me, it looks like your problem is that you're using , as a decimal point character in your file instead of . that gnuplot understands natively. There are two possible solutions. The first I found from googling, but can't test:
set locale
or
set locale "ja_JP.UTF-8" #gnuplot complains this isn't available for me ...
or perhaps set decimalsign local "..."
The second solution is a little less elegant, but it involves converting all of your , to . in your datafile. That's a trivial thing to do using sed:
sed -e 's/,/\./g' length.dat > length2.dat
Now you can just plot using length2.dat and it should work OK (it did for me). As an aside, I think that's quite a nicely colorful plot. The pngcairo terminal does a good job with it.

Resources