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
Related
Can you set timefmt one way for X and another for Y? My data looks like:
2019-05-08 00:14:29.000
2019-05-08 00:14:27.000
2019-05-07 22:08:09.000
2019-05-07 22:08:08.000
My code looks like:
## X axis
set xdata time
set timefmt "%Y-%m-%d"
set format x "%m:%d"
set xrange ["2019-01-01":"2019-10-30"]
set xlabel "Date (mm:dd)" font "Times, 12"
# Y axis
set ydata time
set timefmt "%H:%M:%S"
set format y "%H:%M"
set yrange ["00:00":"23:59"]
set ylabel "Time Of Day(hh:mm)" font "Times, 12"
plot "file.data" using 1:2 with points
I see the axes look right but there is no data. If I remove the second 'set timefmt' it complains about no Y data.
I didn't see an example of this using gnuplot. Any suggestions? I have many hundreds of datapoints and 50+ files of data.
I'm also regularly confused and puzzled with data/time format. My suspicion is that if you have two time axes you specify the input format first set timefmt "%Y-%m-%d" and later set timefmt "%H:%M:%S". This is not especially dedicated to an axis. So, when it comes to plotting, gnuplot takes the current (the latter) format which is of course wrong for the date in column 1. But I could be wrong with this explanation.
Anyway, if you specify the format in the plot command (timecolumn(1,"%Y-%m-%d")) it should be fine.
Code:
### two date/time axes
reset session
$Data <<EOD
2019-01-08 10:14:29.000
2019-05-08 00:14:27.000
2019-05-07 14:08:09.000
2019-05-07 22:08:08.000
2019-10-07 12:08:08.000
EOD
## X axis
set xdata time
set timefmt "%Y-%m-%d"
set format x "%m/%d"
set xrange ["2019-01-01":"2019-10-30"]
set xlabel "Date (mm/dd)" font "Times, 12"
# Y axis
set ydata time
set timefmt "%H:%M:%S"
set format y "%H:%M"
set yrange ["00:00":"23:59"]
set ylabel "Time Of Day(hh:mm)" font "Times, 12"
plot $Data using (timecolumn(1,"%Y-%m-%d")):2 w p pt 7
### end of code
Result:
It may be best to do this without using timefmt or set *data time at all, although this makes setting and explicit xrange more cumbersome.
$TIMES << EOT
2019-01-08 00:14:29.000
2019-05-08 03:14:27.000
2019-05-07 22:08:09.000
2019-08-07 22:08:08.000
EOT
set xtics time format "%m/%d"
set ytics time format "%H:%M"
set xlabel "Date (mm/dd)" font "Times, 12"
set ylabel "Time Of Day(hh:mm)" font "Times, 12"
set key tmargin reverse Left
set xrange [strptime("%Y-%m-%d","2019-01-01"):strptime("%Y-%m-%d","2019-10-30")]
plot $TIMES using (timecolumn(1,"%Y-%m-%d")) : (timecolumn(2,"%H:%M:%S")) with points
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
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?
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
i have a csv file from 5 year malware data collected there are 2 columns the dates and the ips every date have 1 or more ips example
1/5/2013 12.234.123
1/5/2013 45.123.566
1/5/2013 100.546.12
1/6/2013 42.153.756
3/4/2014 75.356.258 etc... (every day for 5 years)
now i am trying to get the percentage difference between every month example:
November 2014 - 10%
December 2014 - 15%
i tried to put the percentage on y axis and in x2 axis but im getting some crazy results i am new to gnuplot and im still learning it here is the code i have right now:
set title 'Results Per Month'
set xlabel 'Date'
set ylabel 'Percentage'
set terminal png size 2800,900
set datafile sep ','
set xdata time
set timefmt '%Y/%m/%d'
set xrange['2009/3/22':'2014/12/02']
set xtics 30*24*60*60
set format x '%Y/%m'
set autoscale x2fix
set x2tics
set x2range[0:*]
set format x2 "%g %%"
set xtics nomirror rotate by -90
set grid ytics xtics
set ytics 10
set yrange [0:*]
set term png
set output 'file.png'
plot 'export.csv' using (timecolumn(1) - (tm_mday(timecolumn(1))-1)*24*60*60):(1) smooth frequency w lp pt 7 ps 2 notitle, \
'' using (($1-$2)/$1*100):x2ticlabels(2) axes x2y1 with points ps 2 lw 2
I would suggest you to use some external script for such kind of preprocessing (you can also do this on-the-fly). Yes, you can do this in gnuplot in two steps, but can become quite complicated and requires some more profound knowledge of gnuplot.
Here is a working script, but I won't go into detail about the many different aspects of the actual implementation:
set xdata time
set timefmt '%Y/%m/%d'
set datafile separator ','
set table 'temporaryfile.dat'
set format x '%Y/%m/%d'
plot 'export.csv' using (timecolumn(1) - (tm_mday(timecolumn(1))-1)*24*60*60):(1) smooth frequency
unset table
set y2tics
set ytics nomirror
set timefmt '"%Y/%m/%d"'
set format x '%b %Y'
set xtics rotate by 90 right
set datafile separator white
set yrange[0:*]
x0=x1=0
plot 'temporaryfile.dat' using 1:(strcol(3) eq "i" ? $2 : 1/0) w lp pt 7 ps 2 title 'IP count', \
'' using 1:(x1=x0, x0=$2, strcol(3) eq "i" ? ($0 == 0 || x0 == 0 ? 0 : (x0-x1)/x0 * 100.0) : 1/0) axes x1y2 w lp title 'percentual change'
Basically, first you plot the result data of smooth frequency into a second data file. Then you can plot this, and to the calculations for the percentages.
Please note, that I used a timeformat which corresponds to your test data (and the data of your previous question), which doesn't correspond with what you have in your script! Please pay attention to this.
Also note, that the timefmt before the actual plot must be extended by quote signs which are written around the dates in tmp.dat.
Finally, the strcol(3) eq 'i' is necessary to circumvent a gnuplot bug, which causes a last line to be written with invalid data.