I have troubles creating a heat map with gnuplot for data with different scales.
Consider the following sample data set:
0.100 1.000 10.0
0.010 1.000 20.0
0.001 1.000 40.0
0.100 10.00 20.0
0.010 10.00 40.0
0.001 10.00 80.0
0.100 100.0 40.0
0.010 100.0 80.0
0.001 100.0 160.0
If I plot it using a heatmap, it only seems to be correct if I scale the x-values such that they are in the same range as the y-values.
Please find below an illustrating example. Only the second plot gives me the correct values of the heat map (high values in the top left corner, low values in the bottom right corner):
set multiplot layout 2,1
set pm3d
set dgrid3d 20,20
set view map
set xlabel 'unscaled'
splot 'data.dat' u 1:2:3
set xlabel 'scaled by factor 1000'
splot 'data.dat' u ($1*1000):2:3
How can I achieve this also for the non-scaled values?
Any help is appreciated. Many thanks.
Here you go :
set dgrid3d 20,20
set pm3d explicit
set view map
set table "interpolated_data.dat"
splot 'data.dat' using ($1*1000):2:3
set output 'heatmap.png'
set terminal pngcairo
set multiplot layout 2,1
unset table
unset dgrid3d
set pm3d
unset surface
set xlabel 'scaled by factor 1000'
splot 'interpolated_data.dat' u 1:2:3
set xlabel 'unscaled'
splot 'interpolated_data.dat' u ($1/1000):2:3
The scaled plot looks correct, but I'm not sure whether it really is correct. At least there seems to be an artifact in the lower left corner, a local maximum which probably should not be there. You can see it better if you remove set view map:
I think the reason is the dgrid3d. It does some fancy weighting of the neighboring points which can lead to unexpected results.
My suggestion would be to use a linear interpolation by removing set dgrid3d 20,20 and using set pm3d interpolate 20,20. This gives the following picture:
Finally, your data somehow asks for at least to try a logscale plot:
My script for the last plot follows. Nothing special compared to yours. I had to specify xrange for the unscaled plot, and it is longer because of the 4 plots.
reset
set terminal png size 1200,800
set output "data_log.png"
set logscale x
set logscale y
set multiplot layout 2,2 title "With \"interpolate\" and logscale"
set pm3d at s interpolate 20,20
set hidden3d
set xlabel 'unscaled'
set origin 0.5,0.5
set xrange [0.001:0.1]
splot 'data.dat' u 1:2:3 notitle
set autoscale x
set xlabel 'scaled by factor 1000'
set origin 0.5,0.0
splot 'data.dat' u ($1*1000):2:3 notitle
set view map
set xlabel 'unscaled'
set origin 0.0,0.5
set xrange [0.001:0.1]
splot 'data.dat' u 1:2:3 notitle
set autoscale x
set xlabel 'scaled by factor 1000'
set origin 0.0,0.0
splot 'data.dat' u ($1*1000):2:3 notitle
unset multiplot
set output
Related
set xrange [-2:2]
set yrange [-2:2]
set xlabel 'X'
set ylabel 'Y'
set samples 300
set isosamples 300
set lmargin screen 0.1
set rmargin screen 0.9
set tmargin screen 0.9
set bmargin screen 0.1
set multiplot
set pm3d map
set palette grey
unset colorbox
splot x**2+y**2 < 1 ? 0:0.2
unset pm3d
plot sin(x) lc 0
This code displays the problem - different positionning of x/y labels by splot, plot.
Although you have the margins identical for both plots for some reason (which I don't know) the labels are not at identical positions. However, since the label values are identical anyway, no need for trying to plot the second labels on top of the first ones. Simply skip all labels and tics of the second plot.
Code:
### remove shifted tics in multiplot
reset session
set xrange [-2:2]
set yrange [-2:2]
set xlabel 'X'
set ylabel 'Y'
set samples 300
set isosamples 300
set lmargin screen 0.1
set rmargin screen 0.9
set tmargin screen 0.9
set bmargin screen 0.15
set multiplot
set pm3d map
set palette grey
unset colorbox
splot x**2+y**2 < 1 ? 0:0.2
unset pm3d
unset xlabel
unset ylabel
unset xtics
unset ytics
plot sin(x) lc 0
unset multiplot
### end of code
Result:
It is quite possible that you can create your composite plot entirely with splot and therefore do not need to use multiplot, bypassing the whole issue. I realize that the example you give may be over-simplified but as it stands the plot can be created by
set xrange [-2:2]
set yrange [-2:2]
set trange [-2:2]
set xlabel 'X'
set ylabel 'Y'
set samples 300
set isosamples 300
set view map
set pm3d at b
set palette grey
unset colorbox
splot x**2+y**2 < 1 ? 0:0.2 with pm3d, \
'+' using 1:(sin($1)):(0) with lines lc "blue" lw 3
With gnuplot 5.2.8, the figure can be created with just one plot command:
pl [-2:2][-2:2] sample [0:2*pi] "+" us (cos(x)):(sin(x)) with filledcurve, sin(x)
Thus splot and multiplot are not needed here.
sample is needed to redefine the parameter range (only in case of first plot argument).
A documentation is here: https://github.com/gnuplot/gnuplot/blob/4a7a11e6b528ea362c943cf632fd21a518b15c54/docs/gnuplot.doc#L7856
PS: As you see it also works without $1 for your cairolatex terminal.
The last couple of hours I've been trying to produce an acceptable-looking plot of a 3D-Object. Now i'm totally stuck at somehow making Gnuplot draw the borders in respect to my 3D-object in a right way. The code I use is this:
reset
set term pngcairo enhanced size 800,600
set output "plot.png"
set grid xtics ytics ls 3 lw 1 lc rgb 'gray'
set xzeroaxis
set yzeroaxis
set samples 30,30
set isosamples 30,30
set style line 100 lt 5 lw 0.5 lc black
set palette gray
set cbrange [-1:1]
unset colorbox
set pm3d depthorder hidden3d implicit
set pm3d lighting primary 0.50 specular 0.6
set parametric
set urange [0:2*pi]
set vrange [0:2*pi]
set xrange [-3.1:3.1]
set yrange [-3.1:3.1]
set zrange [-1.1:1.1]
set xyplane at -1
set view 121,115
set xtics offset first 0,0, -0.1
set ytics offset first 0,0, -0.1
set ytics -2,1,2
set xtics -2,1,2
unset border
set border 4095 front lt black linewidth 2.000 dashtype solid
splot (2+cos(u))*cos(v),(2+cos(u))*sin(v),1*sin(v) lc rgb '#666666'
set output
If you plot that code it results in an image like this:
3D-Object Plot
As you can see the layering of Borders/Axes and Graph is somehow messed up. I spent some time playing around with different terminal types, or set border back / front / behind, or basically all the other options, but i could not succeed in making Gnuplot draw this the right way, which means, the borders surround my Object.
The only compromise solution i could find, is, if i choose certain different view-points Gnuplot gets it all right. But for the one i want the drawing does not work..
I would be very happy about any suggestions or hints!
zooming in gnu plot is done by multi plot.
But what if we have zoom a particular subplot in multi plot?
It is like a multi plot within another multi plot.
need help!
Within a multiplot environment you can create plots wherever you want, their positions and sizes are set with the commands set origin and set size.
It is up to you whether the single plots are positioned side by side or one into another like in this example.
set terminal pngcairo
set output "multiplot.png"
set samples 1000
set xzeroaxis
set multiplot
set origin 0,0
set size 1,1
set xrange [-15:15]
plot cos(x) * x**2, sin(x) * x**2
set nokey
set origin 0.3, 0.07
set size 0.5, 0.45
set xrange [-2:2]
set yrange [-4:2]
set xtics 1
set ytics 2
replot
set origin 0.45, 0.14
set size 0.3, 0.2
set xrange [-0.1:0.1]
set yrange [-0.002:0.004]
set ytics 0.002
set xtics 0.1
replot
unset multiplot
Note that the values for origin and size are given relative to the complete picture, not relative to the previous plot.
I'm trying to plot two different sets of data on the same graph using gnuplot. The first set must be plotted as boxerrorbars, and the second one as linespoints. But, when I run the code bellow on gnuplot I get the following error:
"/home/flav/salaak/src/www/plots/signature.ranking.1.EnergyPKG.gnu", line 20: warning: Skipping data file with no valid points
plot '//home/flav/salaak/src/www/plots/ranking.1.EnergyPKG.dat' using 0:2:3:xtic(1) with boxerrorbars fc rgb 'forest-green' title 'EnergyPKG [W]' axes x1y1, '//home/flav/salaak/src/www/plots/ranking.1.EnergyPKG.dsz.dat' u 1:2 w linespoints t 'Data Size bytes' axes x1y2
^
"/home/flav/salaak/src/www/plots/signature.ranking.1.EnergyPKG.gnu", line 20: all points y2 value undefined!
The code:
set terminal pngcairo enhanced font 'arial,10' fontscale 1.5 size 1024, 768
set output '/home/flav/salaak/src/www/plots/signature.ranking.1.EnergyPKG.png'
unset border
set grid
set style fill solid 0.25 noborder
set boxwidth 0.5 absolute
set title 'Ranking 1 '
set xlabel 'Query.Job'
set ylabel 'EnergyPKG [W]'
set style histogram errorbars gap 2 lw 1
set style data histograms
set xrange [-0.5:3]
set yrange [0:]
set key under autotitle nobox
set ytics nomirror
set y2tics nomirror
set y2range [0:]
set y2label 'Data Size [bytes]'
plot '//home/flav/salaak/src/www/plots/ranking.1.EnergyPKG.dat' using 0:2:3:xtic(1) with boxerrorbars fc rgb 'forest-green' title 'EnergyPKG [W]' axes x1y1, \
'//home/flav/salaak/src/www/plots/ranking.1.EnergyPKG.dsz.dat' u 1:2 w linespoints t 'Data Size bytes' axes x1y2
ranking.1.EnergyPKG.dat:
q22.2 23.0008220833333 0.237935519166793
q16.2 22.988090297619 1.18050606267611
q07.4 10.6937465361916 0
ranking.1.EnergyPKG.dsz.dat:
q22.2 23359824
q16.2 1987871
q07.4 38
I can't figure out where the problem really is.
The values in the first column aren't valid numerical values, you must use the zeroth column also when plotting the linespoints (as you already do for the boxes):
dir ='/home/flav/salaak/src/www/plots/'
plot dir.'ranking.1.EnergyPKG.dat' using 0:2:3:xtic(1) with boxerrorbars axes x1y1,\
dir.'ranking.1.EnergyPKG.dsz.dat' u 0:2 w lp axes x1y2
And, please restrict the script you post to a bare minimum, which however still shows the problem. All those ranges, labels, tic settings etc are superfluous and make it more difficult to identify the problem.
I'm trying to add some guiding lines over a pm3d map using Gnuplot.
Below is the code I use to plot pm3d map (my pm3d map).
set terminal post eps enhanced color solid "Helvetica" 16
set encoding iso_8859_1
set hidden3d
set pm3d map
set view map
unset surface
set size square
splot "map.ene" with image
set xlabel "RC1 ({\305})"
set ylabel "RC2 ({\305})"
set cblabel "{/Symbol D}G (kcal/mol)" offset 1,0,0
set xrange ["1":"11"]
set yrange ["5.5":"9.5"]
set cbrange ["-3.1":"0.0"]
set xtics 1
set ytics 1
set cbtics 1
set mxtics 2
set mytics 5
unset key
set palette defined (-3.1 "red", -2.5 "yellow", -1.5 "green", -0.5 "blue", 0 "white")
unset colorbox
set output "map.eps"
replot
map.ene is in the format below:
1.000 5.500 0.00000 i
Now I want to add a vertical line (x=5.5) over the pm3d figure. I searched old posts and found similar questions already been asked by others. Seems there are two possible solutions:
1) prepare a separate data file for the line (x.dat, 5.5,y,0.0) then use command below to plot.
splot "map.ene" with pm3d, "x.dat" using 1:2:(0.0) with points linecolor rgb "black"
2) use "multiplot" facility in Gnuplot.
I tried both, neither worked. I've been playing this for a while but sill not sure how I should modify my original pm3d code to add guiding lines.
you can draw lines in gnuplot:
set arrow from first 5.5, graph 0 to first 5.5, graph 1 nohead
type help coordinates to better tune the above command.