3

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?

2 Answers 2

4

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)
Sign up to request clarification or add additional context in comments.

Comments

0

You are running into two problems:

  • The string-equality operator in Gnuplot is eq, not ==.
  • Data extracted for plotting is not of the string type (I assume it’s a float), so you cannot apply string operations to it.

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.)

2 Comments

Thanks for your reply. Well it gave me the following error: input record number 4097, file u_output.txt source line number 1 ^ Need full using spec for x time data
@Queen: Then heed the error message. (Also see my edit.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.