Gnuplot: CSV and Date on X-Axis - gnuplot

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

Related

Time conversion does not work in gnuplot

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?

Weather data displayed with gnuplot

i'm currently trying to plot weather data with gnuplot using a text document containing a utc timestamp in the first column, and the temperature in the second and third.
set term png size 1920,660
set output "Today.png"
set datafile missing '0'
set ylabel "Temperature"
set grid ytics
set timefmt "%s"
set format x "%H:%M:%S"
set xdata time
set xtics rotate
plot "Data.dat" using 1:2 with lines lt rgb "red" t "Inside", "Data2.dat" using 1:3 with lines lt rgb "blue" t "Outside"
This is working and displaying the graphs except for one thing:
The data is automatically updated every couple hours. So when creating the image at 10 am it will display data from 0-10 am. Instead I want it to always display one complete day at a time, so over the course of the day, you can see the graph "grow" from left to right.
I tried inserting the following code:
set xrange ["00:00:00":"23:59:59"]
but it does not display anything then.
Any suggestions on how to accomplish that?

Remove weekend gaps in gnuplot for candlestick chart

I am trying to plot some financial candlestick charts with gnuplot. The problem is that there is no data during the weekends, and I don't want these gaps to be showed. Picture and code included below.
set datafile separator ","
set xdata time
set timefmt"%Y-%m-%d"
set xrange ["2015-10-22":"2016-02-06"]
set yrange [*:*]
set format x
plot 'head.dat' using 1:2:4:3:5 notitle with candlesticks
As you have one entry per working day, instead of using the dates as abscissae you can use the line number:
plot 'head.dat' using 0:2:4:3:5 notitle with candlesticks
Then I guess you'll ask how to restore the dates on the x-axis. You can use xticslabel :
set xtics rotate 90
plot "head.dat" u 0:2:4:3:5:xticlabels(1) notitle with candlesticks
If you want to avoid having every label shown use this everyNth function posted by dir, e.g. every fifth label:
set datafile separator ","
everyNth(countColumn, labelColumnNum, N) = \
( (int(column(countColumn)) % N == 0) ? stringcolumn(labelColumnNum) : "" )
set xtics rotate 90
plot "head.dat" using 0:2:4:3:5:xticlabels(everyNth(0, 1, 5)) notitle with candlesticks
Results in:

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

Plotting some date related records

I'm having some trouble with plotting dataset that looks like this:
2250,2011-07-05 02:00:00.0,null,4,0,0,24,0,626,2250,abc
2250,2011-07-05 04:00:00.0,null,2,0,0,24,0,302,2250,abc
2250,2011-07-05 03:00:00.0,null,9,0,0,24,0,687,2250,abc
2250,2011-07-03 03:00:00.0,null,4,0,0,24,0,423,2250,abc
2250,2011-07-02 05:00:00.0,null,3,0,0,24,0,1525,2250,abc
2250,2011-07-02 04:00:00.0,null,4,0,0,24,0,636,2250,abc
2250,2011-07-11 04:00:00.0,null,1,0,0,24,0,33,2250,abc
2250,2011-07-02 03:00:00.0,null,2,0,0,24,0,495,2250,abc
I'm using this kind of gnuplot script:
set datafile separator ","
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S.0"
set xrange ["2011-06-29 01:00:00.0":"2011-07-11 04:00:00.0"]
set xtics border in scale 1,0.5 nomirror rotate by -45 offset character 0, 0, 0
plot "input.csv" using 1:8 title "total times" with linespoints
I keep getting an error:
all points y value undefined!
which according to docs means that my plot definition did not produce any points. However by analyzing it by hand, it looks unreasonable - the xrange looks ok and the plot columns are also not null.
Any ideas?
With this script, you try to plot the first column as your x-axis and the eighth column as your y-axis. With set xdata time you specify, that the datatype of your x-axis is set to time/date.
Unfortunately your first column is not of type date nor time. Try
plot "input.csv" using 2:8 title "total times" with linespoints
and the script will run perfectly.
(At least it does on my machine ^^).

Resources