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.
Related
my gnuplot script plot bar graphs in the following 2D format:
using the following sctipt:
set term pngcairo size 800,600
set termoption noenhanced
set title "$file_name" font "Century,22" textcolor "#b8860b"
set tics font "Helvetica,10"
#set xtics noenhanced
set ylabel "Fraction, %"
set xlabel "H-bond donor/aceptor, residue"
set yrange [0:1]
set ytics 0.1
set grid y
set key off
set boxwidth 0.9
set style fill solid 0.5
plot '<cat' using 2:xtic(1) with boxes
In order to add values above the bars, I've tried to modify it to
plot '<cat' using 0:2:xtic(1) with boxes, '' u 0:2:2 w labels offset 0,1
but the values were not added to the bars, with the following warning
"/dev/fd/63" line 17: warning: Skipping data file with no valid points
I can only test for Windows, but I assume cat under Linux is the equivalent for type under Windows.
So, what is your filename? I would say your filename is simply missing. Check help piped-data.
Something like the following should work:
plot '<cat myDataFile.dat' using 0:2:xtic(1) with boxes, '' u 0:2:2 w labels offset 0,1
But then, what is the difference to using directly the filename?
plot 'myDataFile.dat' using 0:2:xtic(1) with boxes, '' u 0:2:2 w labels offset 0,1
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
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 have two data series:
2.72121 -1326.8380227810
2.81569 -1326.8407684060
2.91018 -1326.8428301680
3.00466 -1326.8448265650
3.09915 -1326.8470902260
3.19364 -1326.8497826100
3.28812 -1326.8530603940
3.38261 -1326.8571516770
3.47710 -1326.8628214990
3.57158 -1326.8694360090
3.66607 -1326.8759488230
3.76056 -1326.8820177910
3.85504 -1326.8875129030
3.94953 -1326.8923946780
4.04401 -1326.8966652370
4.13850 -1326.9003601490
4.23299 -1326.9035228070
and
4.23299 -1326.9035228070
4.13850 -1326.9003601490
4.04401 -1326.8966652370
3.94953 -1326.8923946780
3.85504 -1326.8875129030
3.76056 -1326.8820177910
3.66607 -1326.8759488230
3.57158 -1326.8694360090
3.47710 -1326.8628214990
3.38261 -1326.8571516770
3.28812 -1326.8530603940
3.19364 -1326.8497826100
3.09915 -1326.8470902260
3.00466 -1326.8448265650
2.91018 -1326.8428301680
2.81569 -1326.8407684060
2.72121 -1326.8380227810
which are the same data series but in reverse order. That's for the first series:
and that's for the second one:
The full gnuplot code is:
set loadpath 'C:\Users\sjojungfrun\Programs\gnuplot\palettes'
load 'parula.pal'
set lmargin 10
unset key
set xtics font 'arial,16'
set ytics font 'arial,16'
set grid ytics
e_kcal = 627.509391
b_angs = 0.52918
stats "reverse_scan_coord.dat" nooutput
e_min = STATS_min_y
plot "reverse_scan_coord.dat" u ($1 * b_angs):(($2 - e_min) * e_kcal) w lp pt 7 lw 2 lc 11 #smooth csplines
I am using the Windows Version 5.0 patchlevel 5 of gnuplot.
Am I doing something wrong? I am really surprised about this auto-ordering feature.
If you don't reverse the xrange, the x-values are ranged from smaller/less positive to larger/more positive.
By default, gnuplot connects points in the plot that were neighboring data points in the data file.
In your case one can thus indeed say that the graph is drawn from right to left, as mentioned in the comments.
Although the question is answered and OP's misunderstanding is clarified, let me add some code for creating a plot which would satisfy OP's initial understanding, i.e. gnuplot would automatically adjust the axis direction depending on the direction of the data.
So, strictly speaking, this is not an answer, but an addition which might be useful to somebody for some (very special) cases.
Well, typically, either you know beforehand what direction your data has or you always want to plot it with either increasing (noreverse) or decreasing (reverse) x-values.
What the code does: checking the first and last datapoint and if the last one is smaller than the first one it sets the axis direction to reverse otherwise to noreverse. If I overlooked a simple gnuplot option for this, please let me know.
Code:
### automatically set axis in same direction as data
reset session
$Data1 <<EOD
2.72121 -1326.8380227810
2.81569 -1326.8407684060
2.91018 -1326.8428301680
3.00466 -1326.8448265650
3.09915 -1326.8470902260
3.19364 -1326.8497826100
3.28812 -1326.8530603940
3.38261 -1326.8571516770
3.47710 -1326.8628214990
3.57158 -1326.8694360090
3.66607 -1326.8759488230
3.76056 -1326.8820177910
3.85504 -1326.8875129030
3.94953 -1326.8923946780
4.04401 -1326.8966652370
4.13850 -1326.9003601490
4.23299 -1326.9035228070
EOD
$Data2 <<EOD
4.23299 -1326.9035228070
4.13850 -1326.9003601490
4.04401 -1326.8966652370
3.94953 -1326.8923946780
3.85504 -1326.8875129030
3.76056 -1326.8820177910
3.66607 -1326.8759488230
3.57158 -1326.8694360090
3.47710 -1326.8628214990
3.38261 -1326.8571516770
3.28812 -1326.8530603940
3.19364 -1326.8497826100
3.09915 -1326.8470902260
3.00466 -1326.8448265650
2.91018 -1326.8428301680
2.81569 -1326.8407684060
2.72121 -1326.8380227810
EOD
DirectionCheck(data,colX) = \
sprintf('stats %s u (column(0)==0 ? x0=column(%d):x1=column(%d)) nooutput; \
if (x0>x1) { set xrange[:] reverse } \
else { set xrange[:] noreverse }',data,colX,colX)
set multiplot layout 2,1
set ytic 0.02
SetDirection = DirectionCheck('$Data1',1)
#SetDirection
plot $Data1 u 1:2 w lp pt 7 lc "red"
SetDirection = DirectionCheck('$Data2',1)
#SetDirection
plot $Data2 u 1:2 w lp pt 7 lc "blue"
unset multiplot
### end of code
Result:
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.