I'm trying to generate a heat map from data (https://pastebin.com/AgivvGgX). The data are not in the "matrix" form.
I tried to use pm3d map and I obtained the following plot:
I also tried to use dgrid3d and view map:
set view map
set pal def
set dgrid3d 40,40,3
splot "plot.dat" using 1:2:3 u pm3d
And I obtained the following result:
Both the plots are not correct. The dgird3d keyword creates artifacts where there are not data points.
I obtained a nice plot using the code:
set view map
set pal def
splot "plot.dat" using 1:2:3 with points pointtype 5 pointsize 1 palette linewidth 8
Here the result
I would like to obtain a map similar to the latter one, but not with discrete points or squares but as a continuous heat map and have a white background where data are not present. Is it possible?
Since your data is irregular, you should use dgrid3d. It has various options (see help dgrid3d), here is a picture I've got while trying different kernels and options:
set view map
set palette defined (0 'white', 1 'blue', 2 'green', 3 'yellow', 4 'red')
set dgrid3d 100,100 exp kdensity 10,10
splot 'plot.dat' w pm3d palette
set dgrid3d 100,100 gauss kdensity 30,30
replot
Related
I'd like to 3Dplot one data set, and contour plot a different dataset into a single combined plot. (The contour dataset is related with gradients of the 3Dplot, for those interested). The code adapted from here works OK, except in one respect: if I use set zrange to scale my 3D plot, contours disappear. Autoranged 3Dplot does not look good, although contours appear OK then, that's why I'd like to apply a custom range. I suspect the problem has something to do with the contours getting ranged, too, in a way that leaves no contour left. But I'm not experienced enough with Gnuplot to see whether this is really the case, or how to solve the problem.
This code...
reset
set ztics 5
#set zrange [10 : 25] #nowriteback
set view 135,60
set contour base #surface
set cntrlabel font ",7"
set datafile missing "NaN"
set clabel
set cntrparam levels discrete 0.3, 0.4, 0.6, 1.0, 1.5
splot 'out011_Io.txt' nonuniform matrix with lines notitle nocontour, \
'out011_FlxN.txt' nonuniform matrix with lines title "{/Symbol F}_{N}" enhanced nosurface
...creates this plot: excessively flattened 3D plot with OK contours ,
while activating the zrange...
reset
set ztics 5
set zrange [10 : 25] #nowriteback
set view 135,60
set contour base #surface
set cntrlabel font ",7"
set datafile missing "NaN"
set clabel
set cntrparam levels discrete 0.3, 0.4, 0.6, 1.0, 1.5
splot 'out011_Io.txt' nonuniform matrix with lines notitle nocontour, \
'out011_FlxN.txt' nonuniform matrix with lines title "{/Symbol F}_{N}" enhanced nosurface
...creates this plot: good 3D plot, no visible contours.
Original data can be found here: out011_FlxN.txt and out011_Io.txt
Suggestions from more knowledgeable are highly appreciated.
If you check help contour, gnuplot offers the options to plot the contour
set contour {base | surface | both}
Unfortunately, not at a custom level as you requested.
So, my suggestion for a workaround would be the following:
plot the data and the contour into a table, e.g. datablock $Cont. This datablock will contain the data and the contour lines (in your case 5) and each sub-block separated by 2 empty lines.
unset contour
plot $Cont, but except the first block. In your case via index 1:5.
Explanation of:
for [i=1:LevelCount] $Cont u 1:2:(10):(column(-2)) index i w l lc var ti columnhead(3)
Plotting the blocks 1 to 5 of $Cont at a constant z-level (10) using variable color lc var determined by pseudocolumn (column(-2)) with columnhead(3) as keytitle. Apparently, in your case there are only 4 contour lines, i.e. none at 0.3.
Code:
### contour plot at custom level
reset session
set contour base
set cntrparam levels discrete 0.3, 0.4, 0.6, 1.0, 1.5
set table $Cont
splot "out011_FlxN2.txt" nonuniform matrix
unset table
unset contour
set key at screen 0.16, screen 1 title "{/Symbol F}_{N}"
set view 135,60
set xyplane relative 0
LevelCount = 5
splot "out011_Io.txt" nonuniform matrix w l notitle, \
for [i=1:LevelCount] $Cont u 1:2:(10):(column(-2)) index i w l lc var ti columnhead(3)
### end of code
Result:
Without a minimal example including datafiles, it's difficult to answer for sure, but it could be because your second file has values outside the zrange you would like to impose for the first one. E.g., the code:
set cntrparam levels discrete -.5,.5
set contour base
splot 10*(sin(x/3)*sin(y/3)+2), sin(x/3)*sin(y/3) nosurface
does produce contours, but there too if you specify a zrange which does not include -0.5 and possibly 0.5, these contours are not shown. Since there is no axes keyword for splot (contrary to plot), to the best of my knowledge you're left with tricks to make the data in the second file fit in the range of the data of the 1st. Since the range of the 1st is [10:25] and the one of the second [0.3:1.5], adding 10 is good. But then you have to produce key "by hand", else the contours would be labelled 10.3, 10.4,.... Here is the corrected code:
reset
set ztics 5
set zrange [10 : 25] #nowriteback
set view 135,60
set contour base #surface
set cntrlabel font ",7"
set datafile missing "NaN"
set clabel
NSURFACES=1 #change if plotting more surfaces
SHIFT=10
LEVELS="10.3, 10.4, 10.6, 11.0, 11.5"
set cntrparam levels discrete #LEVELS
set style line 100 lc rgb "white"
splot 'out011_Io.txt' nonuniform matrix with lines notitle nocontour, \
'out011_FlxN.txt' nonuniform matrix using 1:2:($3+SHIFT) with lines notitle enhanced nosurface, \
for [i=0:words(LEVELS)] 1/0 w l ls (i==0)?100:i+NSURFACES title (i==0)?"{/Symbol F}_{N}":sprintf(("%.1f"),word(LEVELS,i)-SHIFT)
NB:
A cleaner solution would be to use stats on both and calculate what offset should be added to the 2nd file rather than hardsetting 10.
From version 5.2, you can replace 1/0 by the cleaner keyentry keyword.
My question is about my code in gnuplot. I want to plot data with pm3d map and Matrix and want to plot the z value in each datapoint as well. I tried this:
set pm3d;set pm3d interpolate 0,0;set pm3d map;
set Palette rgb 33,13,10;splot 'filepath' Matrix
It is all working fine but I cannot plot the z values so I tried this one
splot 'filepath' Matrix using 1:2:(sprintf(%g,$3)) with labels
but this is also not working. Can anybody help me?
as #Bodo, wrote... "not working" is not enough and not helpful to others.
With your code, you must have gotten some error messages, provide them as well.
Several mistakes in your script:
set palette instead of set Palette
splot 'filepath' matrix instead of splot 'filepath' Matrix
sprintf("%g",$3) instead of sprintf(%g,$3)
To your actual problem:
splot requires 3D coordinates + label text, i.e. in your case x:y:z:z or 1:2:3:3
So, the following code is probably doing what you intended to do.
set pm3d
set pm3d interpolate 0,0
set pm3d map
set palette rgb 33,13,10
splot 'filepath' matrix u 1:2:3:(sprintf("%g",$3)) with labels
I am trying to plot some experimental data points (defined by x, y, and z) and and some "iso-z" lines. To plot contour lines, the data need to be in a grid format. I tried to follow proposed elsewhere, where by means of dgrid3d the experimental, nongrid data, are converted by interpolation into grid points, and use these new data points to draw the contour lines.
The script looks as follows:
reset
set term pdf color enhanced font 'Arial, 18' size 13.5cm,9.2cm
set out 'phasediag.pdf'
#Here I convert the data points, stored in 1f.dat into a grid format.
set table '1f-grid.dat'
set dgrid3d 50,50
splot '1f.dat' u 3:4:2
unset table
#Here I would like to draw the countour lines, to be used after in the plot.
set contour base
set cntrparam level auto 5
unset surface
set table 'cont.dat'
splot '1f-grid.dat'
unset table
# Load the palette color definition.
load 'parula.pal'
set logscale cb
set cbrange[1e5:1e9]
set format cb '10^{%1.1T}'
set cblabel 'Mw / g mol^{-1}' offset 2.5,0
set format x '%1.1f'
set format y '%1.1f'
set label '1{/Symbol F}' at 0.4,6.3
set label '2{/Symbol F}' at 2.15,3
plot[0:2.7][2.5:7] '1f.dat' u 3:4:2 with points pt 5 palette, '2f.dat' u 3:2 with points pt 7 lc rgb "black"
set out
Unfortunately, I get the following error when I try to draw the contour lines in the cont.dat file:
Warning: Cannot contour non grid data. Please use "set dgrid3d".
The error surprises me a bit, as the data produced in the first where produced using dgrid3d and are in grid format.
By commentig out the section in which the contour lines should have been drown, I get the following output:
I would simply draw some lines at constant z-values. Any hint for that?
Thanks in advance,
Leo
I already have a nice 3D plot, with only contour projection from a data file. And I want to add a simple function on it. How can I do this?
here the code:
set autoscale
set terminal png
set contour
set output 'Corrugation_uwtp_HorizontalWind.png'
set pm3d map
set samples 50; set isosamples 50
unset key
set palette rgbformulae 33,13,10
set xlabel "Horizontal distance"
set ylabel "Vertical height"
splot "CORRUGATION_C_UWTP.dat" u 1:2:3
and I want to add following functin:
h(x)=sin(x)
Thank you for your help
Not possible directly, you have to make it in three steps, as 2D plot:
1st plot the contour to a table:
set contour; unset surface
set table $datatable
splot dataf
unset table
2nd plot the contours and your function
plot for [i=0:5] $datatable index i, f(x)
3rd plot the datafile as a coloured surface
replot dataf with image
If you use a gnuplot version prior to 5.0, you have to plot the table output to a temporary file instead of $tablename.
I want to plot a surface where each face has a different pm3d style. I tried the following:
reset
set format x "%.6f"
set format y "%.6f"
set format z "%.6f"
set xrange[-10:10]
set xtics border -10,5,10
set yrange[-10:10]
set ytics border -10,5,10
set cbrange[0:2]
set pm3d depthorder
set palette defined (0 'green', 1 'red', 1 'blue', 2 'black')
splot "pm3d1_1.dat" using 1:2:3:($3/200) with pm3d, "pm3d1_1.dat" using 1:2:($3-1):($3/200+1) with pm3d
where 'pm3d1_1.dat' is the function z=xx+yy with z varying between 0 and 200 (x,y between -10 and 10). The problem is that the output doesn't look how I expected when viewed from certain points of view, like this one:
I'd appreciate any help and I'd like to know if there is an alternative to plot a surface with different pm3d styles on each face. Thanks.
I guess it has to with the way depthorder sorts the quadrangles. Don't know if this could be fixed. To extend your question, here is an example without external data file, which also shows the problem:
set xrange[-10:10]
set yrange[-10:10]
set zrange[-1:200]
set isosamples 20
set pm3d depthorder
set ticslevel 0
set view 65,28
set palette defined (0 'green', 1 'red', 1 'blue', 2 'black')
splot '++' using 1:2:(z=$1**2+$2**2):(z/200.0) w pm3d,\
'++' using 1:2:(z=$1**2+$2**2, z-1):(z/200.0+1) w pm3d
Result (with 4.6.4):
Don't know of any other way to plot this. Maybe I'll submit the above script as bug report.