gnuplot:用数据中的颜色填充曲线

gnuplot: filledcurves with color from data

我想将 filledcurves 与调色板一起使用。

我的数据是这样的:

0 0 0 1 1 1 1 0 0.5
2 2 2 3 3 3 3 2 0.6

我的绘图命令:

set terminal pngcairo size 800,600
set output "test.png"
set style fill solid 1.0 noborder
unset border
unset xtics
unset ytics
plot '< awk ''{print ,,,"\n",,,,"\n",,,,"\n",,,,"\n",,,,"\n"}'' rect.txt' \
using 1:2:3 with filledcurves fillcolor palette notitle

不幸的是,这只会产生黑色方块,而我希望它们是彩色的。有没有办法用 gnuplot 获得正确着色的图形?

编辑:

按照建议使用:

set terminal pngcairo size 800,600
set output "test.png"
set style fill solid 1.0 noborder
unset border
unset xtics
unset ytics
file = 'rect.txt'
lines = system(sprintf('wc -l %s | cut -d'' '' -f 1', file))
frac(x) = system(sprintf('awk ''{if (NR==%d){ print  }}'' %s', x, file))
rect(x) = sprintf('awk ''{if (NR==%d){ print ,,,"\n",,,,"\n"}}'' %s', x, file)
plot for [i=1:lines] '< '.rect(i) using 1:2:3 with filledcurves palette frac frac(i) notitle

与rect.txt的内容:

0 0 0 1 1 1 1 0 0.5
2 2 2 3 3 3 3 2 0.6
2 2 2 1 1 1 1 2 0.2

产生以下结果:

filledcurves 绘图样式不支持使用文件中的数据按调色板着色。这里的主要问题是,通常,在使用 palette 时,人们希望根据某些数据值更改单个区域内的颜色。

要从调色板的小数位置为单个矩形着色,您可以使用 palette frac <value>。这需要您遍历所有矩形。

为了正确使用 filledcurves,您需要不同的数据格式,例如

x1 y1_low y1_high
x2 x2_low y2_high

既然你正在使用 awk,你可以提取更多信息用于实际绘图:

set terminal pngcairo size 800,600
set output "test.png"
set style fill solid 1.0 noborder
unset border
unset xtics
unset ytics
file = 'rect.txt'
lines = system(sprintf('wc -l %s | cut -d'' '' -f 1', file))
frac(x) = system(sprintf('awk ''{if (NR==%d){ print  }}'' %s', x, file))
rect(x) = sprintf('awk ''{if (NR==%d){ print ,,,"\n",,,,"\n"}}'' %s', x, file)
plot for [i=1:lines] '< '.rect(i) using 1:2:3 with filledcurves palette frac frac(i) notitle

有了数据文件

0 0 0 1 1 1 1 0 0.5
2 2 2 3 3 3 3 2 0.6
2 2 2 1 1 1 1 2 0.2

你得到输出