Time conversion does not work in gnuplot - linux

I have the following snippet to have a graph output via gnuplot.
set datafile separator ","
set title "Memory"
set xlabel "Values"
set ylabel "Date"
set ydata time
set timefmt "%H"
set format y "%d/%m/%Y"
set key left top
set grid
plot 'memory-memory-buffered_combined' using 0:2 titl "1" with lines,\
'memory-memory-cached_combined' using 0:2 title "2" with lines
cat
pause -1
However, when I have the result it starts from 1970.
The first 5 lines of the csv I am reading;
epoch,value
1478193413.596,72910
1478193473.412,134432
1478193413.158,65449
1478193411.929,60157
So, it is actually November 2016.
Which part of my script should be different?

set datafile separator ","
set title "irq"
set xlabel "Date"
set ylabel "Values"
set xdata time
set timefmt "%s"
set format x "%d/%m/%Y"
set key right top
set grid
set terminal jpeg size 3600,2100 enhanced font helvetica 20
set output "irq.jpg"
plot "/irq/irq-16_combined" using 1:2 title "irq-16" with lines
I applied some changes on the script, however it is still inconsistent. Out of 100 scripts which have same pattern and similar files with same column names and values, only one still have output where time starts from 1970. Have any of you experienced such issue?

Related

Gnuplot: CSV and Date on X-Axis

I want to plot cryptocurrency data which is stored in a CSV file.
This is what the CSV file looking at the moment:
Date,Total,XMR,ETH,BTC,BCH
2018-01-20 14:28:09,-48.31496473496111,-2.618473974057121,9.759254879456023,-32.73371338624,-22.72203225412001
2018-01-20 14:32:42,-48.70059864440001,-2.6060653245296663,9.414353657705647,-32.67846583748799,-22.830421140088
2018-01-20 14:35:22,-48.63036074628374,-2.5440902562853935,9.414353657705647,-32.67846583748799,-22.822158310216004
2018-01-20 14:39:31,-48.541251796683724,-2.5440902562853935,9.414353657705647,-32.58935688788797,-22.822158310216004
This is my gnuplot script so far:
set key inside bottom right
set title 'Revenues'
set datafile separator ','
set ylabel 'EUR'
set grid
plot for [col=2:5] "data.txt" using 0:col with lines lw 2 title columnheader
This is what the result looks like:
But as you can see in the first column, every data set has a date which I also want to use. It should appear as the x axis label in a shorter form (e.g. 18/20/01) and the axis should also scale correctly.
My approach was this:
set xtics rotate
set timefmt '%Y-%m-%d %H-%M-%S'
set format x "%d-%m"
set xdata time
plot for [col=2:5] "data.txt" using 0:col:xtic(1) with lines lw 2 title columnheader
...which results in...
As you can see, the label for the x axis is the correct column but it's neither the format I want nor it's scaled (mention that I changed the last date to 2019).
Can you tell me how I can achieve this?
Gnuplot start counting columns at 1:
set datafile separator ","
set timefmt '%Y-%m-%d %H-%M-%S'
set format x "%d-%m"
set xdata time
plot for [col=2:5] "data.txt" using 1:col

Gnuplot group date by year/month

Is my first time using gnuplot and my data file data.csv have the following content
2017-05-28,50000
2017-07-13,100
2017-07-14,3217
2017-01-23,2052
2017-01-24,1954
2017-01-25,1664
Now I'm tryting to plot using the following setup
set title 'My First Graph'
set ylabel 'Total per day'
set xlabel 'Date'
set grid
set term png
set datafile separator ","
set output 'graph.png'
set timefmt '%Y-%m-%d'
set format x "%Y-%m"
plot 'data.csv'
First I got a line 10: Bad format character which I dont understand
You need to add set xdata time and plot with specifying the two columns explicitly:
set title 'My First Graph'
set ylabel 'Total per day'
set xlabel 'Date'
set grid
set datafile separator ","
set timefmt '%Y-%m-%d'
set format x "%Y-%m"
set xdata time
plot 'data.csv' using 1:2
gives

gnuplot, plotting time on x-axis

I have data in the following format in a text file. I want to print the time (hours, mins and secs) on the x-axis. Each timestamp is on a separate line
00:00:05,1
00:00:15,0
01:05:23,1
07:45:00,0
23:21:22,1
Trying the following commands with gnuplot but time isn't printed on x-axis. I would like the time displayed in hours.
set datafile separator ","
set xdata time
set xrange["00:00:00":"24:00:00"]
set timefmt '%H:%M:%S
plot 'data.txt' using 1:2 with boxes
Any help greatly appreciated.
The set timefmt settings are used only for reading the data file. If you don't provide an explicit output format, timedate is assumed automatically. Use set xtics format '%H:%M:%S' to set an explicit output format. Also, parsing of the set xrange strings can be done properly only after you have set the time format:
set datafile separator ","
set xdata time
set timefmt '%H:%M:%S
set xrange["00:00:00":"24:00:00"]
set xtics format '%H:%M:%S'
plot 'data.txt' using 1:2 with boxes

configure gnuplot to handle timeseries like excel

I am trying to graph events over time with gnuplot. Excel's default behavior produces a more readable graph.
I would like my graph from gnuplot to look like Excel's.
set terminal png size 1200,800
set xdata time
set timefmt "%Y-%m-%d_%H-%M"
set output "graph.png"
set xrange ["2015-02-01_08-54":"2015-02-01_23-20"]
set yrange [0:70]
set grid
set xlabel "24-Hour"
set ylabel "Events"
set title "Events"
plot "events.dat" using 1:2 index 0 title "events" with filledcurves ls 1
I've spent many hours manipulating source data and plot.conf, but it's not clear to me what Excel is doing differently.
Gnuplot Output:
Excel Output:
Excel plots with a wrong x-scale: it ignores the time values, and puts the values given in the first column at equidistant x-values as labels.
To get the same behavior with gnuplot, you must use xticlabel to place the values in the first column as tic labels, and use the row number (column 0) as x-values:
set xtics rotate by 90 right noenhanced
plot "events.dat" using 0:2:xticlabel(1) title "events" with filledcurves
Now, this would give you rather unreadable labels, because that are too many. With some tweaks you get a nicer result:
set terminal pngcairo size 1200,800
set output "graph.png"
set yrange [0:70]
set grid y
set xlabel "24-Hour"
set ylabel "Events"
set xtics out nomirror scale 0.5 rotate by 90 right font ',8' noenhanced
plot "events.dat" using 0:2:xticlabel(int($0) % 5 == 0 ? strcol(1) : '') title "events" with filledcurves
Disclaimer: Please use this script only to understand what Excel does and not to reproduce it, because it gives a very wrong impression of the actual time spans in which your events happen!

gnuplot value on Y-axis

I have a file which contains two column data. when plotted, it looks like
Green line is showing mean.
I want to show mean value on Y-axis. Is it possible?
code:
set style data lines
set termoption enhanced
set term png
set title "17th oct"
stats 'data/17-10-2013' using 1:2 nooutput
set xdata time
set timefmt "%s"
set format x "%H"
set output "images/17_DB.png"
plot "data/17-10-2013" using 1:3 title " Data" , STATS_mean_y title " Mean"
Here are three different options to display the value:
set term pngcairo enhanced
set output "images/17_DB.png"
set title "17th oct"
stats 'data/17-10-2013' using 1:2 nooutput
set xdata time
set timefmt "%s"
set format x "%H"
# first option
set ytics add (sprintf('%.1f', STATS_mean_y) STATS_mean_y)
# second option
set ytics add ('' STATS_mean_y)
set rmargin 3
set label left at graph 1.05,first STATS_mean_y sprintf('%.1f', STATS_mean_y)
set style data lines
# third option inside the key label
plot "data/17-10-2013" using 1:3 title "Data" , \
STATS_mean_y title sprintf("Mean = %.1f", STATS_mean_y)
Here some notes about the different options:
The first option is the easiest, but the label could overlap with another label (here with the 0).
The second option adds an empty mayor tic, and places the label on the right side. This requires the right margin to be increased manually (you may need to use another value, e.g. set rmargin 2 and other coordinates).
The third option just places the value in the key (legend) entry.
For a nicer x-axis, you may want to add set autoscale xfix, which gets you rid of the empty space on the right side.

Resources