gnuplot:用数据中的颜色填充曲线 [英] gnuplot: filledcurves with color from data
问题描述
我想在调色板中使用fillcurve曲线.
I would like to use filledcurves with palette.
我的数据如下:
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 $1,$2,$9,"\n",$3,$4,$9,"\n",$5,$6,$9,"\n",$7,$8,$9,"\n",$1,$2,$9,"\n"}'' rect.txt' \
using 1:2:3 with filledcurves fillcolor palette notitle
不幸的是,这只会产生黑色正方形,正如我希望它们被着色一样.有没有办法使用gnuplot实现正确着色的图形?
This unfortunately only yields black squares where as I would like them to be colored. Is there a way to achieve correctly colored figures with 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 $9 }}'' %s', x, file))
rect(x) = sprintf('awk ''{if (NR==%d){ print $1,$2,$4,"\n",$5,$8,$6,"\n"}}'' %s', x, file)
plot for [i=1:lines] '< '.rect(i) using 1:2:3 with filledcurves palette frac frac(i) notitle
包含rect.txt的内容:
with the content of 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
时,人们希望根据某些数据值在单个区域内更改颜色.
The filledcurves
plotting style doesn't support coloring by palette with data from a file. The main issue here is, that usually, when using palette
, one wants to change the color within a single area depending on some data values.
要为从调色板的小数位置获取颜色值的单个矩形着色,可以使用palette frac <value>
.这要求您遍历所有矩形.
To color a single rectangle taking the color value from a fractional position of the palette, you can use palette frac <value>
. This requires you to iterate over all rectangles.
为了正确使用filledcurves
,您需要使用其他数据格式,例如
And for proper use with filledcurves
, you need a different data format, like
x1 y1_low y1_high
x2 x2_low y2_high
由于无论如何都使用awk
,因此您可以提取更多有关实际绘图的信息:
Since you are using awk
anyways, you can extract some more information for the actual plotting:
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 $9 }}'' %s', x, file))
rect(x) = sprintf('awk ''{if (NR==%d){ print $1,$2,$4,"\n",$5,$8,$6,"\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
您将得到输出
这篇关于gnuplot:用数据中的颜色填充曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!