Reputation: 41
I am trying to plot two 2D scalar quantities, one as a heatmap and one as superimposed contour, using the following code:
set contour base
set cntrparam levels incremental 0,0.25,1.25
unset surface
set table cont2.dat
splot 'vr245.gnu'
unset table
reset
set xrange [1:215]
set yrange [0:3.1415925025940E+00]
set cbrange [7:17]
unset key
set view map
set palette rgbformulae 33,13,10
splot 'f_aveFe_245.gnu' u 1:2:3 with pm3d, "cont2.dat" u 1:2:3 w l
As you can see the contour has artifacts on the left. How can I fix this problem? Thank you!
Upvotes: 4
Views: 741
Reputation: 48440
You can selectively switch on or off contouring and plotting of the surface for individual plots in a single splot. Define both pm3d
and contours
in the script, deactivate contours for the first and surface for the
reset
set contour base
set cntrparam levels incremental 0,0.25,1.25
set cntrlabel onecolor
set autoscale xfix
set autoscale yfix
set cbrange [7:17]
unset key
set view map
set palette rgbformulae 33,13,10
splot 'f_aveFe_245.gnu' u 1:2:3 with pm3d nocontour, \
'vr245.gnu' u 1:2:3 w l lc rgb "black" nosurface
Upvotes: 1
Reputation: 13097
It's actually quite interesting. The problem seems to arise for a particular contour corresponding to the level of 1.25
. I think I isolated the issue to the following.
Let's assume that we have a simple datafile as
215 2.55865 1.25
212.185 2.56004 1.25
215 2.87839 1.25
215 0.2632 1.25
212.185 0.252052 1.25
215 0.582938 1.25
now, the gnuplot command(s)
unset key
set view map
set xr [212:215.5]
set yr [0:3]
set xtics nomirror
set ytics nomirror
splot \
'file.dat' w lp, \
'' u 1:2:3:(sprintf("%d", $0)) w labels offset char 0, char -0.5
interestingly, also points 1 and 4 are joined. If the data file is modified as
215 2.55865 1.25
212.185 2.56004 1.25
215 2.87839 1.25
#
215 0.2632 1.25
212.185 0.252052 1.25
215 0.582938 1.25
Gnuplot connects only points 2 and 3 as expected:
What seems to help here is to duplicate the blank line, i.e., this file
215 2.55865 1.25
212.185 2.56004 1.25
215 2.87839 1.25
215 0.2632 1.25
212.185 0.252052 1.25
215 0.582938 1.25
gives indeed disconnected components:
To apply this in your script, one might invoke for example gawk
and merely duplicate all blank lines in the file with calculated contours:
set terminal pngcairo
set output 'fig.png'
set contour base
set cntrparam levels incremental 0,0.25,1.25
unset surface
set table 'cont2.dat'
splot 'vr245.gnu'
unset table
reset
set xrange [1:215]
set yrange [0:pi]
set cbrange [7:17]
unset key
set view map
set palette rgbformulae 33,13,10
splot \
'f_aveFe_245.gnu' u 1:2:3 with pm3d, \
'<gawk "NF==0{print;} {print;}" cont2.dat' u 1:2:3 w l
Alternatively, you might fix this by using plot
to plot the contours instead of splot
:
set terminal pngcairo
set output 'fig.png'
set contour base
set cntrparam levels incremental 0,0.25,1.25
unset surface
set table 'cont2.dat'
splot 'vr245.gnu'
unset table
reset
set xrange [1:215]
set yrange [0:pi]
set cbrange [7:17]
unset key
set view map
set palette rgbformulae 33,13,10
set multiplot
set tmargin at screen 0.9
set lmargin at screen 0.1
set rmargin at screen 0.8
set bmargin at screen 0.1
splot \
'f_aveFe_245.gnu' u 1:2:3 with pm3d
unset xtics
unset ytics
unset border
unset key
plot \
'cont2.dat' w l
Upvotes: 1