问题描述
所以我有这种数据
3.500E2 -0.956862
...
10.00E2 -1.95941
在文件中.
如果我绘制它,它看起来像这样:
现在,我希望曲线下的区域充满可见光谱,像这样:
我已经找到了此论坛帖子,它为我绘制了一个不错的可见光谱,但是我无法进一步向其中添加自己的曲线,因为这似乎是pm3d图.
我该怎么办?
filledcurves
绘图样式无法处理这种渐变填充,但是您可以修改数据文件以将其与pm3d
和splot
一起使用. >
pm3d
样式仅适用于曲面,因此必须编辑数据文件以实际提供曲面网格.
为此,您必须向文件中添加第二个数据块,该数据块在第一列中具有相同的值,第二列的所有值中的最小值作为第二列.两个块必须用空行分隔.
考虑示例数据文件spectrum.dat
:
350 1
400 2
450 5
500 2
550 1
600 3
650 3
700 8
750 4
800 3
850 0
必须从中获取文件
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
这可以通过awk即时完成(由于使用了@TomFenech,命令变得更好了),然后使用您链接的论坛帖子中的函数定义来绘制with pm3d
:
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 '<awk ''NR == FNR {min = !min || $2 < min ? $2 : min; print; next} FNR == 1 {print ""} {$2 = min}1'' spectrum.dat spectrum.dat' using 1:2:(0):1 notitle
请注意,如果您有足够的数据点,则无需插值pm3d面板.在这种情况下,这可能只会给您带来奇怪的伪像(垂直的白色线条).
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?
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 '<awk ''NR == FNR {min = !min || $2 < min ? $2 : min; print; next} FNR == 1 {print ""} {$2 = min}1'' spectrum.dat spectrum.dat' using 1:2:(0):1 notitle
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.
这篇关于gnuplot的可见光谱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!