0

I have a similar question to the original post Visible spectrum with gnuplot but wanted to know how I can do the same thing but without awk? It wasn't obvious to me what to do with the second block of "nulled" data.

Community
  • 1
  • 1
D7000
  • 1
  • 1
  • Out of interest, what is the problem with using `awk` ? – Paul R Sep 24 '15 at 06:12
  • The `pm3d` plotting style is for surfaces only, so you need at least a second line (the second block) to actually have a surface. If you cannot use `awk`, you could also use e.g. a little python script which does the data manipulation for you. That works also on Windows. Or you change your data file manually. – Christoph Sep 24 '15 at 06:39
  • I do not have access to awk on a Windows PC, and am not allowed to install gawk. – D7000 Sep 28 '15 at 23:47

1 Answers1

0

The answers you linked are using awk, but you explicitly asked to do it without awk. Actually, there is an answer to a later question (How to fill a rectangle with colors of visible spectrum in gnuplot?), the example below is slightly modified using a dataset instead of a function.

Yes, you can do it without awk. This script works with gnuplot 5.0.0 (version at the time of question) and if you read the data from a file even with gnuplot 4.6.0.

Note: you have to have enough datapoints such that the colored impulses are overlapping and you won't get white spaces inbetween. If you have a function you can simply increase the sampling, e.g. set samples 1000. If you have a datafile you could either increase the linewith (e.g. lw 3) or you need to resample your values which, however, will be painful with gnuplot alone (see: Resampling data with gnuplot).

Script:

### visible spectrum below curve (approximate colors)
reset 

# create some test data
Gauss(x,x0,A,FWHM) = A * exp(-(x-x0)**2/(2*(FWHM/(2*sqrt(2*log(2))))**2))
f(x) = Gauss(x,555,2000,50) + Gauss(x,440,1000,20) + Gauss(x,555,800,300)
set table $Data
    set samples 600
    plot [380:780] '+' u 1:(f($1)) w table
unset table

set palette defined (380 "black", 400 "dark-violet", 440 "blue",  490 '#00b0c0', 530 "green", 560 "yellow", 620 "red", 780 "black")

unset colorbox
set xrange[380:780]
set xtics out
set key noautotitle

plot $Data u 1:2:1 w impulse lc palette lw 1, \
        '' u 1:2 w l lc rgb "black" lw 2
### end of script

Result:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72