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
Related
I plot with gnuplot the following:
$Data <<EOD
time_,value
1-23:59:58,1
1-23:59:59,2
2-00:00:00,3
2-00:00:01,4
2-00:00:02,5
EOD
set term png size 800,600
set output "ask.png"
set datafile separator comma
set grid
set xdata time
set timefmt "%d-%H:%M:%S"
set format x "%H:%M:%S"
set xtics nomirror
set autoscale xfix
set autoscale x2fix
startnumber=1
xticdata=2
mxticdata=2
set xtics xticdata rotate
set mxtics mxticdata
set x2data
set x2tics startnumber, xticdata rotate
set mx2tics mxticdata
set link x2 via x+1 inverse x-1
plot $Data using 1:2 title columnheader(2)
set output
Data of the column 2 which contains nearly 50,000 records is value of a parameter. set link has to be used to align x-axis and x2-axis. And I want to show x2tic labels for counter/index which must be related to the time(column 1).
The output is alright, but you can see from the attached figure that the labels on x2-axis are big numbers, which is not what I want. I want to get labels like "1,3,5...".
So what's wrong with my code? And how to correct it? Thanks.
If the idea is that the x2 axis should be labeled with the content of column 2 regardless of its numerical relationship to column 1, then you can use:
set xdata time
set timefmt "%d-%H:%M:%S"
set format x "%H:%M:%S"
set xtics nomirror
set x2tics nomirror
set link x2
plot $Data using 1:2:x2ticlabels( int($0+1)%2 ? strcol(2) : "" ) title columnheader(2)
This creates one x2 axis tick label for every data point. The even-numbered ones to blank and the odd-numbered ones are set to whatever is in column 2.
the quickest fix would be
set link x2 via x-86397 inverse x+86397
But it depends what timesteps you have and what numbers you have in column 2. If your time step it is strictly regular and 1 second, and column 2 just counts up, then column 2 is redundant.
Timedata is handled internally as seconds from 01.01.1970 00:00:00.
One day has 86400 seconds. Check help time/date.
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
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 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.
I have the following graph:
first data set display searches.
second data set display clicks.
y1 shows searches scale, y2 shows click scale.
on the x1 I have time values displayed.
I wish to display clicks values (each hour) on x2 (the upper axis).
When I add the command set x2tics it displays the searches data and not the clicks like I wished.
How do I change it so it will display the clicks unit?
Gnuplot script:
set xlabel "Time"
set ylabel "Times"
set y2range [0:55000]
set y2tics 0, 1000
set ytics nomirror
set datafile separator "|"
set title "History of searches"
set xdata time # The x axis data is time
set timefmt "%Y-%m-%d %H:%M" # The dates in the file look like 10-Jun-04
set format x "%d/%m\n%H:%M"
set grid
set terminal png size 1024,768 # gnuplot recommends setting terminal before output
set output "outputFILE.png" # The output filename; to be set after setting
# terminal
load "labelsFILE"
plot 'goodFILE' using 1:3 lt 2 with lines t 'Success' , 'clicksFILE' using 1:2 lt 5 with lines t 'Clicks right Y' axis x1y2
replot
Graph:
graph http://img42.imageshack.us/img42/1269/wu0b.png
Ok, so to get started, here is how you can set a label with the number of clicks as follows (using you data file names):
plot 'goodFILE' using 1:3 lt 2 with lines t 'Success',\
'clicksFILE' using 1:2 lt 5 with lines t 'Clicks right Y' axis x1y2,\
'' using 1:2:(sprintf("%dk", int($2/1000.0))) with labels axis x1y2 offset 0,1 t ''
Just add this as plotting command, and it should work just fine.
To illustrate, how the labels might look like, here is an example with some dummy data:
set terminal pngcairo
set output 'blubb.png'
set xlabel "Time"
set ylabel "Times"
set y2label "Clicks per hour"
set y2range [0:10000]
set yrange [0:1]
set ytics nomirror
set y2tics
set key left
set samples 11
set xrange[0:10000]
plot '+' using 1:1:(sprintf("%dk", int($1/1000.0))) every ::1::9 with labels axis x1y2 offset 0,1 t '',\
'' using 1:1 with linespoints axis x1y2 pt 7 t 'Clicks per hour'
Which gives you: