gnuplot“条件”:三列上的倍数曲线(30?)

我这辈子写的脚本很少,但我几乎只写 bash。从来不需要更多。到现在为止:我想用包装器制作一些图表,这些


1 type1 1

2 type1 2

3 type2 1

4 type1 3

5 type2 2

6 type3 1

模式在哪里:

  • 第一列:排名 {1..10000}

  • 第二列:类别(已知)

  • 第 3 列:正在计算从一开始它看到类别数据的次数占总数的百分比(范围 0 到 1)(我没有英文单词?也许cumulate sum

在电子表格中,第 3 列类似于=(NB.si($B$1:$B4;$B4)/nb.si($B$1:$B;$B4)第 4 行。


我仍在处理如何在 python 中将“累积”总和附加到数据中(我当时只有第一列的两列),这是简单的数学和文本处理脚本。我知道如何在电子表格中实现自动化,在 bash 中有一些想法,但我对 python 知之甚少。但是,这不是我的问题(但我在这里向仁慈的人开放:))


问题

我发现gnuplot可能有帮助,我阅读了各种网站上的手册和一些示例,但我仍然有点困惑:我将如何绘制树曲线,从 0 开始,到 1,用

  • X 斧头:第 1 列

  • Y 轴:第 3 列

  • 曲线:{type1, type2, type3}

http://img2.mukewang.com/641277640001efeb05810353.jpg

慕容3067478
浏览 158回答 1
1回答

繁星淼淼

我会做这样的事情# this function relates every type to an int, convenient for setting the plot stylesf(x) = x eq "type1"? 1: x eq "type2"? 2:0# this tell gnuplot to ignore the result of lines not matchingset datafile missing "NaN"# setting a nice style for every typeset style line 1 linetype 1 linewidth 2 pointtype 3 linecolor rgb "red"set style line 2 linetype 1 linewidth 2 pointtype 3 linecolor rgb "blue"# using a ternary operator to pick out the lines matching that typeplot for [i in "type1 type2"] 'test.dat' u (strcol(2) eq i?$3:NaN) w l ls f(i)得到这个如果需要,您可以for从 plot 命令中删除并仅使用plot 'test.dat' u (strcol(2) eq "type1"?$3:NaN) w l ls 1, 'test.dat' u (strcol(2) eq "type2"?$3:NaN) w l ls 2, 为每种类型显式绘图,并更好地控制每条绘图线的细节。您可以制作另一个函数来为每一行添加标题,类似于f(x)但返回每种类型的字符串而不是 int。我还听说过使用 awk 或内部函数在 gnuplot 中进行累积和的方法,您可以在此处查看gnuplot-cumulative-column-question
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python