(gnuplot 5.2.5, Centos 7) I've tried about 8 google examples and my result is still not even close.
Here is my data:
Timestamp,1016.qmgr,1893.sshd,1.systemd,2017.sshd
2018-11-21.04:23:03,0.1,1.0,4.0,2.0
2018-11-21.04:23:04,0.2,2.0,5.0,4.0
2018-11-21.04:23:05,0.3,3.0,6.0,8.0
Here are my plot settings:
set datafile separator ","
set title "CPU % Usage per task over time"
set ylabel '% CPU'
set xlabel 'Time'
set grid
set term png
set output '10.png'
set key autotitle columnheader
plot for [i=2:5] 'Results.10/CPU.csv' using 1:i'
Basically, I was expecting something like this:
But I got something like this:
Any ideas what to set in the plot parameters file?
You need to tell gnuplot that the first column contains time data, and also what the format is:
set xdata time
set timefmt "%Y-%m-%d.%H:%M:%S"
There are other ways to do it, but that is the simplest way to deal with time specified as a string.
[amended answer]
If you just want the content of the first column printed along x as an opaque text string, the command is:
plot for [i=2:5] 'Results.10/CPU.csv' using 0:i:xticlabels(1)
Because these strings are very long, you probably will need to rotate the labels so they do not overlap:
set xtics rotate by -45
Related
I'm getting confused trying to read a date and time for gnuplot from a text file. The file looks like this:
03.07.2022,13:40:18,119.5,119.5,119.5,17.5,60.00,100.0,27.27,35.1,
03.07.2022,13:30:18,119.5,119.5,119.5,17.5,60.00,100.0,27.27,35.5,
03.07.2022,13:20:18,119.5,119.5,119.5,17.5,60.00,100.0,27.27,35.5,
Here are the relevant lines from my script:
set timefmt "%d.%m.%Y,%H:%M:%S"
plot 'data-nohead.txt' using ($1):2
This gives an error:
"./plot_voltage.gp" line 35: Can't plot with an empty x range!
I don't use gnuplot often, so sometimes do stupid things. Any suggestions are very welcome.
You have a tricky case because your file uses a comma both as a field separator and as a component of the time. This means the time information actually spans columns 1 and 2, while the first non-time information is in column 3. I have added a separate format for the tic labels to confirm that the full time is being read.
set datafile separator comma
set timefmt "%d.%m.%Y,%H:%M:%S"
set xdata time
set xtics time format "%d.%m.%Y\n%H:%M"
plot 't.dat' using 1:3
I know how to get a point plot in netlogo by choosing plot-pen-mode to be 2. Doing this gives a plot with tiny dots. In other programming environments, I can choose the marker size and shape as well as the color. Can this be done in netlogo?
As far as I know, you can't. The plots in Netlogo can give you a quick look at what the data looks like but for further handling, you will need to export the data and use another program. A simple way for exporting data is using file-open, file-type and file-print to create a csv file.
to initiate-output
if file-exists? "output-file.csv" [ file-delete "output-file.csv" ]
;Make sure to start with an empty file
file-open "output-file.csv"
file-type "x-value," ;use file-type and a comma to stay on the same line
file-print "y-value" ;use file-print at the end of the line
file-close
end
to generate-output
let x random 10
let y random 10
file-open "output-file.csv"
file-type word x "," ;use file-type and a comma to stay on the same line
file-print y ;use file-print at the end of the line
file-close
end
I have CSV file with the following structure:
headerString1;headerString2;...;headerStringN
doubleNumber1;doubleNumber2;...;doubleNumberN
... many other doubleNumberRows
I want to plot histograms from each of the columns in individual files - this is something that works - and I want to take the title for each individual plot from the CSV-file, first row. I searched a lot, but could find a solution. Up to now this is my gnuplot code:
set datafile separator ";"
set style data histogram
binwidth=20
set boxwidth binwidth-2
bin(x,width)=width*floor(x/width)
# No legends!
unset key
do for [COL=1:10] {
set title sprintf("%d", columnheader(COL)) <--- This always tells me it is a number, "%s" does not work
FILE = sprintf("%s%02d%s","Histogram",COL,".png")
set term png giant font helvetica 24 size 1440, 1080
set output FILE
plot "myCSVFile.CSV" using (bin(column(COL),binwidth)):(1.0) smooth freq with boxes lc 1
}
columnheader(COL) is a number (?), at least I can convert it via sprintf("%d", columnheader(COL)) to a number string which is "-2147483648" for all plots. The output looks like this:
How do I retrieve the headerString# strings and use it as title in my individual plot?
You have access to the columnhead string only in very specific contexts, for example within a plot command. Setting the plot title is not one of them (set title doesn't even know which data file you are going to be using), but creating legend entries is. So you could position the legend where the title usually appears.
For example, given the datafile test.csv
First Column;Second Column
-900;-700
-1100;-800
-1000;-650
you could use
set term push
set datafile separator ";"
set style data histogram
set style fill solid 1
binwidth=20
set boxwidth binwidth-2
bin(x,width)=width*floor(x/width)
set key outside top center samplen 0
do for [COL=1:2] {
FILE = sprintf("%s%02d%s","Histogram",COL,".png")
set term pngcairo
set output FILE
plot "test.csv" using (bin(column(COL),binwidth)):(1.0) smooth freq notitle with boxes lc 1, \
NaN title columnhead(COL) with lines lc rgb "white"
set output
}
set term pop
and get
Here I separated the plot that displays the histogram from the plot that generates the legend entry so that the sample picture does not show up in the legend.
Alternatively, if you know the possible column titles beforehand you could also use
do for [name in '"First Column" "Second Column"'] {
set title name
plot "test.csv" using (bin(column(name),binwidth)):(1.0) smooth freq notitle with boxes lc 1
}
I found a workaround for my problem:
Instead of extracting the column header from the file (which were desirable), I create a title array which I have to copy from the csv file :(
Code:
titles = "columnHeader1 ... columnHeaderN"
do for [COL=1:N] {
FILE = sprintf("%s%02d%s","Histogram",COL,".png")
set term png giant font helvetica 24 size 1440, 1080
set output FILE
set title word(titles, COL)
plot "InputFileName.CSV" using (bin(column(COL),binwidth)):(1.0) smooth freq with boxes lc 1
}
This works, but is a couple of clicks more than desired...
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?
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)
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.)
I have
FileSFC1: contains certain data
FileSFC2: contains some other data
Now what I need to do is divide the second column of FileSFC1 with the second column of FileSFC2 and then plot this result. So something of the form:
plot ( FileSFC1 using 1:1 / FileSFC2 using 1:1 ) * 100
So basically the plot would be a percentage of the columns in the two files. Please help.
Gnuplot can only manipulate columns of data that are from the same 'file' or data stream. What you can do is use the plot '< bash command' construction. When the argument to plot starts with < what happens is the rest of the argument is interpreted as a bash command, and the output of that command is what is plotted. So:
plot '< paste FileSFC1 FileSFC2' u (100*$2/$4)
This assumes that both files have two columns, and you want to plot the percentage of the 2nd column in each file. To perform manipulations on data columns, the syntax is to enclose the argument to using in parentheses and prefix column numbers with a dollar sign.
Andyras' answer is the one you are looking for.
I just wanted to add that with this construct, you can't use bash's process substitution<(, which is the shame because in most of those cases, you have to do additional stream precessing (grepping or removing lines, etc.)
For this, you need the answer to this question Gnuplot and Bash process-substitution, which I'll briefly exemplify here :
# Will concatenante FileSFC1 with the first 200 lines of FileSFC2
plot '< exec bash -c "paste <(cat FileSFC1) <(head -n 200 FileSFC2)"' u (100*$2/$4)