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
How can I add vertical grid line only at midnight every day when using a time xscale in gnuplot? I want to be able to produce multiple plots with different time spans from 24-hours to 2-months. I want to put a vertical grid line at midnight every day on the graph so I can easily distinguish individual days on the graph. This is what my gnuplot script looks like now:
set terminal png size 900, 300
set output "images/temps.png"
set xdata time
set timefmt "%m/%d/%y %H:%M"
set datafile separator ","
set ylabel "Temperature \260F"
set xlabel "Time"
set grid ytics
set y2tics mirror
set y2label "Temperature \260F"
set grid xtics lc rgb "#888888" lw 1 lt 0
plot [:][:] 'data.csv' using 1:2 title "" with lines
With this script, I get vertical grids added at automatic intervals. Those intervals are meaningful intervals, but I want to be able to force the spacing.
I found my answer:
set xtics 86400
This is in seconds. 86400 seconds in 24 hours.
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:
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!
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 ^^).