Visible spectrum with gnuplot

前端 未结 2 1367
谎友^
谎友^ 2021-01-05 06:27

So I have this kind of data

3.500E2 -0.956862
...
10.00E2 -1.95941

in a file.

If I plot it it looks like this:

2条回答
  •  再見小時候
    2021-01-05 07:04

    The filledcurves plotting style cannot handle such gradient filling, but you can modify your data file to use it with pm3d and splot.

    The pm3d style works only for surfaces, so you must edit your data file to actually provide a surface grid.

    For this you must add a second data block to your file, which has the same values in the first column, and the minimum of all values of the second column as its second column. Both blocks must be separated by an empty line.

    Consider the example data file spectrum.dat:

    350 1
    400 2
    450 5
    500 2
    550 1
    600 3
    650 3
    700 8
    750 4
    800 3
    850 0
    

    From that you must get a file

    350 1
    400 2
    450 5
    500 2
    550 1
    600 3
    650 3
    700 8
    750 4
    800 3
    850 0
    
    350 0
    400 0
    450 0
    500 0
    550 0
    600 0
    650 0
    700 0
    750 0
    800 0
    850 0
    

    That can be done on-the-fly with awk (the command got much better thanks to @TomFenech) and then plotted with pm3d using the function definitions from the forum post you linked:

    lmax = 780; lmin = 380
    k=lmax-lmin
    set cbrange [lmin:lmax]
    r(x)=x<440?-(x-440)/(440-380):x<510?0:x<580?(x-510)/(580-510):x<=780?1:0
    g(x)=x<440?0:x<490?(x-440)/(490-440):x<580?1:x<645?-(x-645)/(645-580):0
    b(x)=x<490?1:x<510?-(x-510)/(510-490):0
    f(x)=x<420?0.3+0.7*(x-380)/(420-380):x<700?1:0.3+0.7*(780-x)/(780-700)
    set palette functions f(k*gray+lmin)*r(k*gray+lmin),g(k*gray+lmin),f(k*gray+lmin)*b(k*gray+lmin)
    
    set pm3d map interpolate 0,1
    set autoscale xfix
    splot '

    enter image description here

    Note, that you don't need to interpolate the pm3d palette if you have enough data points. That might only give you strange artifacts (white vertical lines) in that case.

提交回复
热议问题