Reputation: 11
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.
Upvotes: 1
Views: 277
Reputation: 25734
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:
$Cont
. This datablock will contain the data and the contour lines (in your case 5) and each sub-block separated by 2 empty lines.$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:
Upvotes: 1
Reputation: 2332
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:
stats
on both and calculate what offset should be added to the 2nd file rather than hardsetting 10.1/0
by the cleaner keyentry
keyword.Upvotes: 0