【问题标题】:Plotting a dataset with condition over a column in gnuplot在gnuplot中的列上绘制具有条件的数据集
【发布时间】:2017-09-28 01:01:45
【问题描述】:

我想绘制以下数据集。

+---------------+-----------+-------------+-----+----+----+--------------------+-------------------+----+----+----+----+--------------------+--------------------+------------------+--------------------+-----------------+------+
|   time_stamp_0|sender_ip_1|receiver_ip_2|count|rank|  xi|                  pi|                  r| ip5| ip4| ip3| ip2|            variance|             entropy|    pre_chi_square|          chi_square| total_chi_square|attack|
+---------------+-----------+-------------+-----+----+----+--------------------+-------------------+----+----+----+----+--------------------+--------------------+------------------+--------------------+-----------------+------+
|10:37:37.000985|   10.0.0.3|     10.0.0.1| 9345|   1|1796|1.070090957731407...|0.19218833600856072|1211|1157|4812|1796|6.982982177427692E-5|9.783410080138751E-4|3.3954177346722574|0.001890544395697248|13.58167093868903|     1|
|10:37:37.000995|   10.0.0.3|     10.0.0.1| 9345|   2|1796|2.140181915462814...|0.19218833600856072|1211|1157|4812|1796|3.497253089848578...|0.001808335909968907| 17.00510593066335|0.009468321787674473|13.58167093868903|     1|
|10:37:37.001002|   10.0.0.2|     10.0.0.1| 9345|   3|1796|3.210272873194221...|0.19218833600856072|1211|1157|4812|1796|8.436389877417202E-4| 0.00258233850119472|41.021252923981834|0.022840341271704808|13.58167093868903|     1|

我需要有一个图来显示“time_stamp_0”上的“等级”,仅适用于 sender_ip_1="10.0.0.3"。 我有以下代码:

set timefmt '%H:%M:%S'
set xdata time
set format x '%H:%M:%S'
//I have a problem with the below code
plot  "test.txt" using 1:($2=="10.0.0.3"?$5:1/0)

但是绘制的图形不正确。 实际上,似乎对数据没有应用过滤,图和没有过滤的图一样!

我应该提一下,数据框位于文件 (test.txt) 中,并且没有任何标题。

你能帮帮我吗?

【问题讨论】:

    标签: plot gnuplot


    【解决方案1】:

    使用eq 进行字符串相等检查并使用strcol 获取列的字符串值:

    plot  "test.txt" using 1:(strcol(2) eq "10.0.0.3" ? $5 : 1/0)
    

    【讨论】:

      【解决方案2】:

      你遇到了两个问题:

      • Gnuplot 中的字符串相等运算符是eq,而不是==
      • 为绘图提取的数据不是字符串类型(我假设它是浮点数),因此您不能对其应用字符串操作。

      我看不到在 Gnuplot 中解决第二个问题的方法。但是,在为您处理条件之前,您可以通过 AWK 之类的东西管道传输所有内容:

      plot "<awk '{print $1, ($2==\"10.0.0.3\" ? $5 : \"nan\")}' test.dat" u 1:2
      

      (请注意,您仍然需要注意 ASCII 表格式,例如,通过 SED 删除所有 | 字符。)

      【讨论】:

      • 感谢您的回复。好吧,它给了我以下错误:输入记录号 4097,文件 u_output.txt 源行号 1 ^ 需要完整使用 x 时间数据的规范
      • @Queen:然后注意错误信息。 (另请参阅我的编辑。)
      猜你喜欢
      • 1970-01-01
      • 2014-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多