Reputation: 571
I would like to plot the following dataset.
+---------------+-----------+-------------+-----+----+----+--------------------+-------------------+----+----+----+----+--------------------+--------------------+------------------+--------------------+-----------------+------+
| 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|
I need to have a plot that shows me the "rank" over the "time_stamp_0" only for sender_ip_1="10.0.0.3". I have the following code:
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)
However the plotted graph is not correct. In fact, it seems that, no filtering applies on the data and the graph is as same as the graph without filtering!
I should mention that, the dataframe is inside a file (test.txt) and it does't have any header.
Can you please help me?
Upvotes: 3
Views: 1004
Reputation: 48420
Use eq
for string equality checking and strcol
to get the string value of a column:
plot "test.txt" using 1:(strcol(2) eq "10.0.0.3" ? $5 : 1/0)
Upvotes: 4
Reputation: 4435
You are running into two problems:
eq
, not ==
.I don’t see a way to solve the second problem from within Gnuplot. You can however pipe everything through something like AWK before plotting to handle the condition for you:
plot "<awk '{print $1, ($2==\"10.0.0.3\" ? $5 : \"nan\")}' test.dat" u 1:2
(Note that you still have to take care of your ASCII table formatting, e.g., by removing all |
characters via SED.)
Upvotes: 0