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
Related
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 imported a file into R and let's say the row name is "Hours Studied". Instead of having Hours Studied imported into R, it imports Hours Studied with the annoying ` ` on top of the name. How do I remove it?
I tried doing rownames(data)<- "Hours Studied". But it still returns `Hours Studied` instead of the desired Hours Studied.
Attached an image in this post for clarification
If you use interupted variable names with spaces (e.g. 'my variable') rather than continuous variable names with dashes or underscores (e.g. my_variable, my-variable), R will put "backticks" around the variable or column name to make sure it's clear what is included in the variable name. If you export the data or plot the data in R those ticks will not be present in the displayed variable name.
(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
I have a folder with tons of txt files from where I have to extract especific data. The problem is that the format of the file has changed once and the position of the data I need to extract has also changed. So I need to deal with files in different format.
To try to make it more clear, in column 4 I have the name of the variable and in 5 I have the value, but sometimes this is in a different row. Is there a way to find the name of the variable (in which row) and then extract its value?
Thanks in advance
EDITING
In some files I will have the data like this:
Column 1-------Column 2.
Device ID------A.
Voltage------- 500.
Current--------28
But in some point in life, there was a change in the software to add another variable and the new file iis like this:
Column 1-------Column 2.
Device ID------A.
Voltage------- 500.
Error------------5.
Current--------28
So I need to deal with these 2 types of data, extracting the same variables which are in different rows.
If these files can't be read with read.table use readLines and then find those lines that start with the keyword you need.
For example:
Sample file 1 (with the dashes included and extra line breaks):
Column 1-------Column 2.
Device ID------A.
Voltage------- 500.
Error------------5.
Current--------28
Sample file2 (with a comma as separator):
Column 1,Column 2.
Device ID,A.
Current,555
Voltage, 500.
Error,5.
For both cases do:
text = readLines(con = file("your filename here"))
curr = text[grepl("^Current", text, ignore.case = T)]
Which returns:
for file 1:
[1] "Current--------28"
for file 2:
[1] "Current,555"
Then use gsub to remove anything that is not a number.
I am currently using pdf() to save multiple plots on several pages.
I change page simply by plot.new().
Can I easily get svg() and png() to do the same? Currently only the last plot is saved in the file.
If I cannot have it in the same file, can I have them autogenerate files like: output.png, output2.png.
If you look at the help pages ?png and ?svg you will see that the default file names are "Rplot%03d.png" and "Rplot%03d.svg" respectively. The %03d part of those names means that each time a new plot is created it will automatically open a new file and that part of the file name will be replaced by an incrementing integer. So the first file will be "Rplot001.png" and the next will be "Rplot002.png" etc.
If you don't like the default file name you can create your own and still insert the portion to be replaced by an integer, such as "myplots%02d.png". The % says this is where the number part starts, the 0 is optional, but says to 0 pad the numbers (so you get 01, 02, ... rather than 1, 2, ...), this is generally preferred so that the sorting works out correctly (otherwise you may see the sorting as 1,10,11,2,3,...) and the digit (3 in the default, 2 in my example) is the number of digits, if you will create more than 1,000 plots you should up that to 4, if you know that you will not create 100 then 2 is fine (1 is fine if you know that you will produce fewer than 10). And the d is just an indicator for an integer.