python - gnuplot“条件”:三列上的多重曲线(30?)
问题描述
我一生中写过很少的脚本,但我几乎只做 bash。从来不需要更多。到现在为止:我想用这些包装器制作一些图表
1 type1 1
2 type1 2
3 type2 1
4 type1 3
5 type2 2
6 type3 1
模式在哪里:
- 第一列:排名 {1..10000}
- 第二列:类别(已知)
- 第 3 列:从一开始(我没有英文单词?
cumulate sum
也许?
在电子表格中,3d 列类似于=(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}
多谢你们 !:)
解决方案
我会做这样的事情
# this function relates every type to an int, convenient for setting the plot styles
f(x) = x eq "type1"? 1: x eq "type2"? 2:0
# this tell gnuplot to ignore the result of lines not matching
set datafile missing "NaN"
# setting a nice style for every type
set 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 type
plot for [i in "type1 type2"] 'test.dat' u (strcol(2) eq i?$3:NaN) w l ls f(i)
如果您愿意,您可以for
从绘图命令中删除并使用 just 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
推荐阅读
- c# - 使用 JustMock 模拟参数
- java - 是否有 JSONParser 方法来解析 Java 中的以下字符串结构?
- sql-server - 在自定义 SSMS 报告中获取完整的 @ObjectName?
- python - 如何在 Python matplotlib 中使用分类变量更改 x 轴和 y 轴刻度?
- go - 使用 stompngo 客户端订阅主题
- java - 无法从 Json 字符串创建对象列表
- c# - 从表单 F1 打开表单 F2,然后卸载表单 F1
- android - 带有跟我来的谷歌地图
- javascript - 如何从 JS-Function 写入 ViewData
- python - TimeseriesGenerator feed 和 Dense 层的不兼容形状 - Keras/Tensorflow