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:
Now I want the area under the curve filled with the visible spectrum, like this:
I already found this forum post, which draws me a nice visible spectrum, but I can't further add my own curve into it, as this appears to be a pm3d plot.
What can I do?
I regularly hit this question whenever I want to plot the VIS spectrum. I elaborated a bit over the answer by @Christoph and wanted to make the color part simpler. Which is indeed possible, using the HSV space, instead of RGB. In addition, it allows simple calculation of complementary color for absorption spectra.
The hue angle gnuplot must be in range 0:1, in all other sources 0-360. The angle 0 corresponds to red (assumed 780nm). The ultraviolet edge is at 300 degree of hue space.
Gnuplot automatically scales the input data into the cbrange, so we need to put the cbrange maximum deep into the UV and cut off the magenta part of Hue (at 300 degree = 0.83 gnuplot Hue). Finally, the hue is inversely proportional to th wavelength, so the palette function is (1-gray), the Saturation and Value are set to constant 0.5
The rest of the plot is identical
The
filledcurves
plotting style cannot handle such gradient filling, but you can modify your data file to use it withpm3d
andsplot
.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
:From that you must get a file
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: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.