我有一些以下格式的数据:
10.0 1 a 2
10.2 2 b 2
10.4 3 a 2
10.6 4 b 2
10.8 4 c 10
11.0 4 c 20
...其中第三列基本上表示属于“单独”数据集;因此,我想用红色显示属于“a”的样本,用蓝色显示属于“b”的样本等(使用 gnuplot 版本 4.4 patchlevel 2)。
我设法以某种方式获得“样本”样式作为“脉冲
”和“点
”样式之间的混合;并通过 在 Gnuplot 4.0 中选择线条类型和颜色 ,设法采用单独的颜色 - 这就是我所取得的成绩(basictest.gnuplot):
#!/usr/bin/env gnuplot
print "Generating data..."
# to specify data inline in script:
# only system can work, as it is quoted;
# but still have to escape newlines!
system "cat > ./inline.dat <<EOF\n\
10.0 1 a 2\n\
10.2 2 b 2\n\
10.4 3 a 2\n\
10.6 4 b 2\n\
10.8 4 c 10\n\
11.0 4 c 20\n\
EOF\n"
print "done generating."
# set ranges
set yrange [0:30]
set xrange [0:4]
# define line styles - can call them up later
set style line 1 linetype 1 linewidth 3 pointtype 3 linecolor rgb "red"
set style line 2 linetype 1 linewidth 2 pointtype 3 linecolor rgb "green"
set style line 3 linetype 1 linewidth 2 pointtype 3 linecolor rgb "blue"
# offset the X axis: instead of 1:2, use: ($1-10):2
# to "mix", use "" for last datset - but must also repeat the "using"!
# ... and plot:
plot 'inline.dat' using ($1-10):2 with impulses linestyle 1,\
"" using ($1-10):2 notitle with points linestyle 1,\
"" using ($1-10):2 notitle with lines linestyle 2,\
'inline.dat' using ($1-10):4 with impulses linestyle 3,\
"" using ($1-10):4 notitle with points linestyle 3
# below just for saving file
#set terminal png
#set output 'basictest.png'
#replot
...看起来像这样:
换句话说,而不是上面的 - 说对于 ($1-10):2,我希望看到第 1st 和第 3rd 示例 ('a') 为蓝色,第 2nd< /sup> 和第 4 个样本('b')为红色,最后两个样本('c')为绿色(我将绿线留在那里只是为了查看风格混合)。
我知道这可以通过编写一个脚本来实现,该脚本将解析原始数据,并从中生成三个表,如下所示:
10.0 1 a 2
10.4 3 a 2
---
10.2 2 b 2
10.6 4 b 2
---
10.8 4 c 10
11.0 4 c 20
...然后可以“单独”绘制 - 但我在徘徊如果< code>gnuplot 也许有一些类似的内部设施?
预先感谢您的任何答复,
干杯!
PS:一些对我有用的链接:
编辑:只是想发布 脚本链接< /a> 我已经接近以我想要的方式可视化数据:
我有点想将标签(添加的“点”作为矩形背景)视为 graphviz 或 节点 href="http://www.texample.net/tikz/examples/simple-flow-chart/" rel="nofollow noreferrer">TikZ,并在它们之间设置那些漂亮的连接线 - 但即使这样已经对我有很大帮助了:) 请注意,这是 wxt
输出 - 其他终端,如 png
或 pdfcairo
将会有一个完全混乱的盒子渲染/标签(并且会需要手动调整)。
I have some data in the following format:
10.0 1 a 2
10.2 2 b 2
10.4 3 a 2
10.6 4 b 2
10.8 4 c 10
11.0 4 c 20
... where the third column basically indicates belonging to a 'separate' dataset; and so I would like to show, say, those samples belonging to 'a' in red, those belonging to 'b' in blue etc (using gnuplot
Version 4.4 patchlevel 2).
I managed to somehow get the 'sample' style as a mix between 'impulses
' and 'point
' styles; and via Choosing line type and color in Gnuplot 4.0, managed to employ individual colors - this is how far I got (basictest.gnuplot):
#!/usr/bin/env gnuplot
print "Generating data..."
# to specify data inline in script:
# only system can work, as it is quoted;
# but still have to escape newlines!
system "cat > ./inline.dat <<EOF\n\
10.0 1 a 2\n\
10.2 2 b 2\n\
10.4 3 a 2\n\
10.6 4 b 2\n\
10.8 4 c 10\n\
11.0 4 c 20\n\
EOF\n"
print "done generating."
# set ranges
set yrange [0:30]
set xrange [0:4]
# define line styles - can call them up later
set style line 1 linetype 1 linewidth 3 pointtype 3 linecolor rgb "red"
set style line 2 linetype 1 linewidth 2 pointtype 3 linecolor rgb "green"
set style line 3 linetype 1 linewidth 2 pointtype 3 linecolor rgb "blue"
# offset the X axis: instead of 1:2, use: ($1-10):2
# to "mix", use "" for last datset - but must also repeat the "using"!
# ... and plot:
plot 'inline.dat' using ($1-10):2 with impulses linestyle 1,\
"" using ($1-10):2 notitle with points linestyle 1,\
"" using ($1-10):2 notitle with lines linestyle 2,\
'inline.dat' using ($1-10):4 with impulses linestyle 3,\
"" using ($1-10):4 notitle with points linestyle 3
# below just for saving file
#set terminal png
#set output 'basictest.png'
#replot
... which looks like this:
In other words, instead of the above - say for ($1-10):2, I'd like to see the 1st and 3rd sample ('a') in blue, 2nd and 4th sample ('b') in red, and the last two ('c') in green (I left the green line there just to see the effect of the style mixing).
I'm aware that this could be achieved by writing a script, that will parse the original data, and generate three tables out of that, as in:
10.0 1 a 2
10.4 3 a 2
---
10.2 2 b 2
10.6 4 b 2
---
10.8 4 c 10
11.0 4 c 20
... which could then be plotted 'separately' - but I was wandering if gnuplot
maybe had some internal facility for something like that?
Thanks in advance for any answers,
Cheers!
PS: Some useful links for me:
EDIT: just wanted to post a link to a script with which I'm getting close to visualizing the data the way I wanted to:
I'm kinda wanting to treat the labels (with the added 'points' as rectagle backgrounds) as nodes in graphviz or in TikZ, and set up those nice connection lines between them - but even this already helps me much :) Note that this is the wxt
output - other terminals like png
or pdfcairo
will have a completely messed up rendering of boxes/labels (and would need to be tuned by hand).
发布评论
评论(2)
这是可能的。 Gnuplot 有一个类似于 C 中的三元运算符。Gnuplot 也会忽略未定义的表达式,例如负数的对数或除以零。将它们放在一起,您可以通过为不满足条件的线生成无效数字来仅绘制满足某些特定条件的线。从问题中稍微简化一下,该方法如下所示:
It is possible. Gnuplot has a ternary operator like in C. Gnuplot also will ignore undefined expressions, such as logarithms of negative numbers or dividing by zero. Putting those together, you can plot only those lines that satisfy some particular condition by producing invalid numbers for those that fail to satisfy the condition. Simplifying a bit from the question, the approach looks like this:
您可以使用 awk 来实现这一点。我不知道我是否会称其为 gnuplot 的“某些内部设施”,但我认为它做了您想要它做的事情:
使用数据文件 Data.csv:
绘制数据
用注意
\"< /code> 转义脚本解析器 ^^.
至于绘图风格问题,您可以利用 gnuplot 提供的全部功能。
You could use awk for that. I don't know if I would call that "some internal facility" of gnuplot, but I think it does what you want it to do:
With a data file Data.csv:
plot the data with
Note the
\"
to escape the script parser ^^.As for plot style issues you can make use of the full spectrum gnuplot has to offer.