GNUPLOT splot color palete matching jetmap - colors

I'm trying to reproduce the following image of rosenbrock function in gnuplot. Source Wikipedia.
My understanding is that the image was created using JET colormap in Matlab/Matplotlib.
Here is my attempt in gnuplot. Macro MATLAB was sourced from here and Macro JET was sourced from here.
I think bringing the orange/yellow all the way down to 500 would be helpful. I'm not sure how to do this in gnuplot.
Also what would be the size to reproduce MATLAB like view?
reset session
set terminal wxt size 800,600 enhanced font 'Verdana,10' persist
set view 50,330
set isosample 30
set xlabel "x"
set ylabel "y"
set zlabel "f(x,y)" rotate
set pm3d
set macros
JET="define (0 0 0 0.5, 1./8 0 0 1, 3./8 0 1 1, 5./8 1 1 0, 7./8 1 0 0, 1 0.5 0 0)"
MATLAB = "defined (0 0.0 0.0 0.5, \
1 0.0 0.0 1.0, \
2 0.0 0.5 1.0, \
3 0.0 1.0 1.0, \
4 0.5 1.0 0.5, \
5 1.0 1.0 0.0, \
6 1.0 0.5 0.0, \
7 1.0 0.0 0.0, \
8 0.5 0.0 0.0 )"
set palette #JET
splot [x=-2:2] [y=-1:3] (1-x)**2+100*(y-x**2)**2 with pm3d notitle
set output

color mapping
I think you will be most of the way there if you change the color mapping to log scale,
and the rest of the way there if you adjust the lower bound on the palette range:
# ... as above ...
set log cb
set cbrange [0.1 : *]
unset mcbtics
replot
bounding box
gnuplot version 5.4:
set wall x1 fillcolor "gray90"
set wall y1 fillcolor "gray90"
set wall z0 fillcolot "gray50"
set xyplane at 0
set border 127
set grid vertical
replot

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:

How to use set offset for only 1 of the datasources in gnuplot?

I want to plot two datasources together in gnuplot: one from a datafile, using text as x-data (with xticlabels and errorbars) and another a constant.
I don't want the xticlabels to reach the sides of the graph, so I use "set offset". However, I do want the constant to reach the sides of the graph.
An example gnuplot script:
set terminal pngcairo size 500, 500
file = 'data.txt'
set output 'plot.png'
set xtics rotate by -45
set yrange [0:1]
set offset 0.5,0.5,0,0
plot file using 0:2:3:xticlabels(1) with yerrorbars notitle,\
0.5 notitle
With the associated data.txt file:
"Europe" 0.4 0.03
"North America" 0.8 0.05
"South America" 0.1 0.08
"Asia" 0.7 0.01
"Africa" 0.9 0.03
"Australia" 0.2 0.03
Provides the following plot:
However, I want the following plot:
How can I achieve this?
You can achieve the same result if you are simply setting the xrange[] properly.
In your case when using xticlabels(1), Europe=0 and Australia=5.
So, simply set xrange[-0.5:5.5]. If the number of items (here 6) is unknown beforehand you could get it either via |$Data| or stats $Data and STATS_records.
Code:
### border when using xticlabels()
reset session
$Data <<EOD
"Europe" 0.4 0.03
"North America" 0.8 0.05
"South America" 0.1 0.08
"Asia" 0.7 0.01
"Africa" 0.9 0.03
"Australia" 0.2 0.03
EOD
set xtics rotate by -45
set xrange [-0.5:5.5]
set yrange [0:1]
plot $Data using 0:2:3:xticlabels(1) with yerrorbars notitle,\
0.5 notitle
### end of code
Result:
You could draw the constant as headless arrow:
set arrow from graph 0, first 0.5 to graph 1, first 0.5 nohead lt 1

how to plot new line given by math formula over pm3d map

ENV
gnuplot 5.0 patchlevel 1
How to plot discrete points on top of pm3d map in gnuplot?,
with code and his mini data
set term postscript enhanced color
set output "gc4-4.eps"
set pm3d map interpolate 10,10
set palette rgbformulae 22,13,-31
sp 'file.dat', 'points.dat' using 1:2:(0) with lines
and Draw a line in a pm3d map, How to mark some points on 2D heat map in gnuplot? are similar solutions. But they use data file instead of math formula.
I also tried How to overlay dots/points scatter plot onto a pm3d map/surface, How to overlay contour plot over pm3d map/surface, How do I plot lines (not grids) using splot?
try some combination of unset surface, set surface explicit, plot ... nosurface.
.
And those are seems solutions for 3d coordinations.
I still do not get the expected result.
Did I miss something? Thank you in advance.
My code below:
set term postscript enhanced color
set output "g.eps"
set multiplot layout 1,2
set pm3d map explicit interpolate 10,10
set palette rgbformulae 22,13,-31
#set contour
#set cntrparam levels incr 0,0.1,0.1
#set linetype 2 linecolor rgb "white" linewidth 2
set tics scale 0.5
set label 1 '(a)' at graph -0.3,1 front
set xlabel "x"
set ylabel "{/Symbol y}"
set xtics 0.8,1.0,2.8
set xrange [0.8:2.8]
set ytics 0.1,0.1,0.9
set yrange [0.1:0.9]
set size 0.4,0.4
#unset surface
#set surface explicit
fx(x) = (x-1.8)**2+0.1
sp "s.data" u 1:2:3 with pm3d notit, fx(x) with line linetype 2 linecolor rgb "white" linewidth 2 tit "line"
#plot fx(x) with lines linetype 2 linecolor rgb "black" linewidth 2 tit "line"
plot fx(x) with lines linetype 2 linecolor rgb "black" linewidth 2 tit "line"
set label 1 '(b)' at graph -0.3,1 front
set xlabel "x"
set ylabel "{/Symbol y}"
set xtics 0.1,0.1,0.9
set xrange [0.1:0.9]
set ytics 0.8,1.0,2.8
set yrange [0.8:2.8]
set size 0.4,0.4
unset surface
set surface explicit
fx(x) = -(2*x-1)**2+1.8
sp "s.data" u 2:1:3 notit, fx(x) with lines linetype 2 linecolor rgb "white" linewidth 2 nosurface tit "line"
#plot fx(x) with lines linetype 2 linecolor rgb "black" linewidth 2 tit "line"
#sp "data/s2.data" u 2:1:3 notit
My mini data of s.data:
# x y z
0.8 0.1 0.3
0.8 0.2 0.2
0.8 0.3 0.1
0.8 0.4 0
0.8 0.5 0
0.8 0.6 0
0.8 0.7 0
0.8 0.8 0
0.8 0.9 0
1.8 0.1 0.3
1.8 0.2 0.2
1.8 0.3 0.1
1.8 0.4 0.2
1.8 0.5 0.3
1.8 0.6 0.4
1.8 0.7 0.4
1.8 0.8 0.5
1.8 0.9 0.5
2.8 0.1 0.3
2.8 0.2 0.4
2.8 0.3 0.5
2.8 0.4 0.5
2.8 0.5 0.6
2.8 0.6 0.6
2.8 0.7 0.6
2.8 0.8 0.7
2.8 0.9 0.7
#
If you know how to plot a data file on a pm3d map, then you can use the table command to plot the function into a data file:
set table "temp_f.dat"
set samples 1000
fx(x) = (2*x-1)**2+1.8
plot fx(x)
unset table
set pm3d map explicit interpolate 10,10
set xrange [0.1:0.9]
set yrange [0.8:2.8]
splot "s.data" u 2:1:3, "temp_f.dat" u 1:2:(0) notitle with lines lw 2 lc 0
This is the result:

How to highlight regions of plot with gnuplot

I'd appreciate if somebody can help with this question.
I am working with a radar (or spiderweb) plot with gnuplot 5.0.0:
The scale and range in all axes is the same. The numbers at and beyond 1 have a special meaning and I would like to highlight that.
I am thinking of three things that would increase visibility:
Simply make the tick mark at 1 (labelled "Limit") boldfaced. How could I highlight just a specific tick and label?
I could also highlight the circular dashed line at level 1
On the plot itself I'd like to have the background colored differently for radius > 1.
How can I achieve either of the three options above? All three would be ideal of course, but just a a minimum differentiation from the rest of that value would help.
This is what generated the plot in the link:
set term x11
set title "My title "
set polar
set angles degrees
npoints = 6
a1 = 360/npoints*1
a2 = 360/npoints*2
a3 = 360/npoints*3
a4 = 360/npoints*4
a5 = 360/npoints*5
a6 = 360/npoints*6
set grid polar 360
set size square
set style data lines
unset border
set grid ls 0
set linetype 1 lc rgb 'red' lw 2 pt 7 ps 2
M=2.2
set arrow from 0,0 to first M*cos(a1), M*sin(a1)
set arrow from 0,0 to first M*cos(a2), M*sin(a2)
set arrow from 0,0 to first M*cos(a3), M*sin(a3)
set arrow from 0,0 to first M*cos(a4), M*sin(a4)
set arrow from 0,0 to first M*cos(a5), M*sin(a5)
set arrow from 0,0 to first M*cos(a6), M*sin(a6)
a1_min = 0
a1_max = 1
a2_min = 0
a2_max = 1
a3_min = 0
a3_max = 1
a4_min = 0
a4_max = 1
a5_min = 0
a5_max = 1
a6_min = 0
a6_max = 1
set label "M1" at M*cos(a1),M*sin(a1) center offset char 1,1
set label "M2" at M*cos(a2),M*sin(a2) center offset char 1,1
set label "M3" at M*cos(a3),M*sin(a3) center offset char 1,1
set label "M4" at M*cos(a4),M*sin(a4) center offset char 1,1
set label "M5" at M*cos(a5),M*sin(a5) center offset char 1,1
set label "M6" at M*cos(a6),M*sin(a6) center offset char 1,1
set xrange [0:1]
set yrange [0:1]
set xtics axis 0,0.5,M
unset ytics
set rrange [0:M]
set rtics (""0,""0.25,""0.5,""0.75,"Limit"1,""1.25,""1.50,""1.75,""2)
set rtics scale 0 format ''
set style fill transparent solid 0.5
set style function filledcurves y1=0.5
set grid noxtics nomxtics noytics nomytics front
plot '-' u ($1==1?a1:($1==2?a2:($1==3?a3:($1==4?a4:($1==5?a5:($1==6?a6:$1)))))):($1==1?(($2-a1_min)/(a1_max-a1_min)):($1==2?(($2-a2_min)/(a2_max-a2_min)):($1==3?(($2-a3_min)/(a3_max-a3_min)):($1==4?(($2-a4_min)/(a4_max-a4_min)):($1==5?(($2-a5_min)/(a5_max-a5_min)):($1==6?(($2-a6_min)/(a6_max-a6_min)):$1)))))) w filledcurve lt 1 title "AAA",\
'-' u ($1==1?a1:($1==2?a2:($1==3?a3:($1==4?a4:($1==5?a5:($1==6?a6:$1)))))):($1==1?(($2-a1_min)/(a1_max-a1_min)):($1==2?(($2-a2_min)/(a2_max-a2_min)):($1==3?(($2-a3_min)/(a3_max-a3_min)):($1==4?(($2-a4_min)/(a4_max-a4_min)):($1==5?(($2-a5_min)/(a5_max-a5_min)):($1==6?(($2-a6_min)/(a6_max-a6_min)):$1)))))) w filledcurve lt 2 title "BBB"
1 2.1
2 1
3 0.1
4 0.5
5 0.5
6 0.1
1 2.1
EOF
1 2.2
2 0.9
3 0.9
4 0.2
5 0.3
6 0.1
1 2.2
EOF
set output
I've taken the liberty to streamline your script a bit, you can now easily adjust the number of arms in the web. Also added a coloured background for 1 >r > M.
Btw., there is no need to enter the first datapoint again at the end to close the contour.
Update: That is, there shouldn't be. However the line between the last and first point is missing then, even with giving the "closed" option to "with filledcurve". I wonder if this is a bug.
set term wxt
set title "My title "
set polar
set angles degrees
set grid polar 360
set size square
set style data lines
set key top left
unset border
set grid ls 0
set linetype 1 lc rgb 'red' lw 2 pt 7 ps 2
M=2.2
npoints = 7
minima = "0 0 0 0 0 0 0" # adjust and add more as necessary
maxima = "1 1 1 1 1 1 1"
a(n) = 360./npoints*n
amin(n) = 0.0 + word(minima,int(n))
amax(n) = 0.0 + word(maxima,int(n))
do for [i=1:npoints] {
set arrow i from 0,0 to first M*cos(a(i)), M*sin(a(i))
set label i sprintf("M%.f",i) at M*cos(a(i)),M*sin(a(i)) \
center offset char 1,1
}
set object 1 circle at 0,0 size M fillc rgb "yellow" behind
set object 2 circle at 0,0 size 1 fillc rgb "white" behind
set xrange [0:1]
set yrange [0:1]
set xtics axis 0,0.5,M
unset ytics
set rrange [0:M]
set rtics (""0,""0.25,""0.5,""0.75,"{/:Bold Limit}"1,""1.25,""1.50,""1.75,""2)
set rtics scale 0 format ''
set style fill transparent solid 0.5
set style function filledcurves y1=0.5
set grid noxtics nomxtics noytics nomytics front
plot '-' us (a($1)):(($2-amin($1))/(amax($1)-amin($1))) \
w filledcurve closed lt 1 title "AAA",\
'-' us (a($1)):(($2-amin($1))/(amax($1)-amin($1))) \
w filledcurve closed lt 2 title "BBB"
1 2.1
2 1
3 0.1
4 0.5
5 0.5
6 0.1
7 0.5
EOF
1 2.2
2 0.9
3 0.9
4 0.2
5 0.3
6 0.1
7 1.8
EOF

histogram with errorbars, pb with the titles of the columns

these are my data : TABLE11-mol+func.dat
#mol PBE optPBE optB86b BEEF Exp IncertitudeBEEF 0
0 PBE-PBE optPBE-vdW1 optB86b-vdW1 BEEF-vdW2 Exp Incert.BEEF 0
1 0.014 0.226 0.210 0.125 0.155 0.10444 0
2 0.033 0.362 0.392 0.223 0 0.16794 0
3 1.742 1.755 2.152 1.432 1.36 0.29116 0
4 1.206 1.441 1.724 1.115 0 0.17857 0
5 0.934 1.533 1.857 1.063 0 0.30034 0
6 0.777 1.514 1.843 0.959 1.295 0.31264 0
7 2.018 2.298 2.858 1.751 0 0.37737 0
8 1.084 1.648 2.336 1.033 1.762 0.60643 0
9 1.504 2.355 3.451 1.449 2.694 1.0138 0
this is my code :
set key left
set auto x
set ylabel "- E_{ads} (eV)" font "Times-Roman, 18"
set yrange [0:3.5]
set ytics (0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5) font "Times-Roman, 18"
set style data histograms
set style histogram errorbars lw 1
set style fill solid border -1
set boxwidth 0.9
set xtics ("Methane" 0, "Ethane" 1, "Ethylidyne" 2, "Ethylene" 3, "Butene" 4, "Cyclohexene" 5, "Butadiene" 6, "Benzene" 7, "Naphtalene" 8) font "Times-Roman, 15"
set xtic nomirror rotate by -45 scale 0
set grid y
plot 'TABLE11-mol+func.dat' using 2:8 ti col, '' u 3:8 ti col, '' u 4:8 ti col, '' u 5:7 ti col, '' u 6:8 ti col
this gives an histogram with wrong title for each color
so I tried to add them "with my hands" with this line instead of the last one :
plot 'TABLE11-mol+func.dat' using 2:8 ti 'PBE', '' u 3:8 ti 'optPBE', '' u 4:8 ti 'optB86b', '' u 5:7 ti 'BEEF', '' u 6:8 ti 'Exp'
and this messes up my histogram, with weird stuffs who appear all over the diagram, and it adds an xtic and bars...
somebody could help me ?
it's even more weird because it use to work some month ago... maybe it's because I have a new version of gnuplot ?
Gnuplot fails to select the correct column to get the title from. It tries to always use the 8th column, as given by the second column in the using option, although this gives the error estimate and not the y-value. You must explicitely give the column number as e.g. ti col(3):
set key left
set yrange [0:3.5]
set ytics 0.5
set style data histograms
set style histogram errorbars lw 1
set style fill solid border -1
set boxwidth 0.9
set xtics ("Methane" 0, "Ethane" 1, "Ethylidyne" 2, "Ethylene" 3, "Butene" 4, "Cyclohexene" 5, "Butadiene" 6, "Benzene" 7, "Naphtalene" 8)
set xtic nomirror rotate by -45 scale 0
set grid y
plot 'TABLE11-mol+func.dat' u 2:8 t col(2), '' u 3:8 t col(3), '' u 4:8 t col(4), '' u 5:7 t col(5), '' u 6:8 t col(6)

Resources