I am using gnuplot 3.7.1 on a Unix system to generate a contour plot.
The data is read from different files that contain the data for the non-
overlapping regions. I am doing something like:
splot 'file1.dat' using 1:2:4 with lines,\
'file2.dat' using 1:2:4 with lines,\
'file3.dat' using 1:2:4 with lines
Everything works fine besides the fact that the colors for the contour
lines
are not consistent with this approach. For instance contour line for the
value "1"
has color "blue" in data region 1 and color "red" in region 2 and
finally "yellow"
in region 3.
I would like to have one single color for a contour level (as if one
would read just
one file) but since I am new to gnuplot I don't know how to achieve
this. Is it
possible to prescribe something like a colortable for contour plots ??
Help and comments are welcome !
Best regards,
Oliver
> splot 'file1.dat' using 1:2:4 with lines,\
> 'file2.dat' using 1:2:4 with lines,\
> 'file3.dat' using 1:2:4 with lines
> Everything works fine besides the fact that the colors for the
> contour lines are not consistent with this approach.
[...]
> I would like to have one single color for a contour level (as if one
> would read just one file) but since I am new to gnuplot I don't know
> how to achieve this.
You've almost found the answer yourself: you have to read just one
file. A single file can contain more than one 'mesh' or 'surface',
i.e. you can combine your three files into a single multi-mesh
datafile. Just be sure you insert two blank lines after each of them.
As you're on a Unix system, you can use the piping feature and
an external shell/awk script to do it on-the-fly:
--- multimsh ---
#! /bin/sh
for f in $@; do
cat $f
echo ""
echo ""
done
--- end --------
With this shell script stored somewhere, you can:
splot '< multimsh file1.dat file2.dat file3.dat' \
using 1:2:4 with lines
and get a single set of contour levels, for all three files.
--
Hans-Bernhard Broeker (bro...@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
> [...]
>
> You've almost found the answer yourself: you have to read just one
> file. A single file can contain more than one 'mesh' or 'surface',
> i.e. you can combine your three files into a single multi-mesh
> datafile. Just be sure you insert two blank lines after each of them.
> As you're on a Unix system, you can use the piping feature and
> an external shell/awk script to do it on-the-fly:
>
> --- multimsh ---
> #! /bin/sh
> for f in $@; do
> cat $f
> echo ""
> echo ""
> done
> --- end --------
>
> With this shell script stored somewhere, you can:
>
> splot '< multimsh file1.dat file2.dat file3.dat' \
> using 1:2:4 with lines
>
> and get a single set of contour levels, for all three files.
> --
> Hans-Bernhard Broeker (bro...@physik.rwth-aachen.de)
> Even if all the snow were burnt, ashes would remain.
Thanks for that little script ! It works but unfortunately I am still not
able to produce a contour plot :-( I only get a blank screen from that
"splot"
command but without error reports from gnuplot ?! Arre there possibilites
to find out what went wrong ? (Is there something like an "error log")
In the meantime I adopted a weird looking workaround for my problem:
I force gnuplot to just plot a single contour line for a specified (discrete)
value and a specified linestyle. Indeed very ugly but it works since I
don't need too many different contour lines.
set linestyle 99 lt 7 lw 1 pt 7 ps 1
[...]
set cntrparam levels discrete 0
splot 'file1.dat' using 1:2:4 with lines linestyle 99
splot 'file2.dat' using 1:2:4 with lines linestyle 99
splot 'file3.dat' using 1:2:4 with lines linestyle 99
Best regards and thanks again for your help,
-Oliver
> Thanks for that little script ! It works but unfortunately I am
> still not able to produce a contour plot :-( I only get a blank
> screen from that "splot" command but without error reports from
> gnuplot ?! Arre there possibilites to find out what went wrong ?
If you got no plot, then the command 'multimsh' didn't produce any
output. Which may happen if either the script was not executable,
or the datafiles weren't found.
> In the meantime I adopted a weird looking workaround for my problem:
> I force gnuplot to just plot a single contour line for a specified
> (discrete) value and a specified linestyle. Indeed very ugly but it
> works since I don't need too many different contour lines.
Actually, on second check, it turns out that my initial advice was
completely incorrect: separate meshes in a file are treated like
separate files, in contour plots, so the whole idea won't work.
But your mentioning of 'cntparam levels' points to the right
direction: You can specify a fixed set of contour levels, which will
then be the same for all datasets. You shouldn't need to specify a
special linestyle for doing that, though, i.e.
set cntrparam levels discrete -1, 0, 1, 2, 5
splot 'file1.dat' using 1:2:4 w l, \
'file2.dat' using 1:2:4 w l, \
'file3.dat' using 1:2:4
should do. You may have to disable the key entries for per
contourlevel, though, which will also deactivate the automatic color
change from one contour level to the next:
set noclabel
(I've no idea why these two actions were coupled into a single
command...)
> [...]
>
> But your mentioning of 'cntparam levels' points to the right
> direction: You can specify a fixed set of contour levels, which will
> then be the same for all datasets. You shouldn't need to specify a
> special linestyle for doing that, though, i.e.
>
> set cntrparam levels discrete -1, 0, 1, 2, 5
> splot 'file1.dat' using 1:2:4 w l, \
> 'file2.dat' using 1:2:4 w l, \
> 'file3.dat' using 1:2:4
>
> should do. You may have to disable the key entries for per
> contourlevel, though, which will also deactivate the automatic color
> change from one contour level to the next:
>
> set noclabel
>
> (I've no idea why these two actions were coupled into a single
> command...)
I have tried this and as you "predicted" the "set noclabel" command
prevents any color/pattern changes from one level to the next. So one
produces a "monochrome" contour plot.
Thank you again for your support !!
Best regards,
Oliver