I'm trying to put dates on my x-axis. My data is plotted and correctly scaled but the x-axis only shows dates (correctly formatted) in a small range of August 1970. Here are the statements I'm using to set up the axis:
set format x "%Y%m%d"
set xrange [ '19400101' : '20200101' ] noreverse nowriteback
set xtics time
set xtics format "%m/%d/%Y"
set xtics border out scale 3.5,1.5 nomirror rotate by 45 offset character -5.5, -2.75
set xtics '19400101', 3.1536e+004, '20200101' norangelimit font "arial,10"
set xlabel "ASDF" # <===== just a test--works fine
set xlabel offset character 0, 0, 0 font "" textcolor lt -1 norotate
If I type show xrange I get [ 1.94001e+007 : 2.02001e+007 ]. Shouldn't I
be getting seconds from 01/01/1970?
What am I missing?
Al Chakrin
there are several things:
first, one needs to make Gnuplot aware that the x-data is indeed time data with set xdata time
further, one should specify the input format of the time data. In this particular case, it would be set timefmt "%Y%m%d" (the commands set format x etc. only control how the date/time data is displayed not how it should be parsed)
in your plot, the tics spacing is specified as 3.1536e+004 (seconds). This will most likely result in warning: Too many axis ticks requested. If this number should represent one year, it should be set to 3.1536e+007 = 365*24*60*60 since the date/time data is internally indeed represented in terms of Unix timestamps (you can check this when you load your script by typing print GPVAL_X_MAX - this gives a value of 1577836800.0 which corresponds to the specified date of 1. 1. 2020)
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.
I am trying to plot some two column data in x-y format. X-axis is in log scale while Y-axis ordinary scale and range from -1 to 1, i.e. set yrange [-1:1].
I could not set ytics as -1:0.2:1.
I am getting an error that increment must be positive.
As shown in help xtics, "start, increment, end" uses comma as the separator, not colon.
set ytics -1, 0.2, 1
I'm trying to plot the following data
29.07.2012 18:45:04;23.6;54
29.07.2012 18:50:04;22.7;56
29.07.2012 18:55:04;22.2;56
29.07.2012 19:00:04;22.0;56
29.07.2012 19:05:04;21.9;57
29.07.2012 19:10:04;21.8;56
29.07.2012 19:15:04;21.8;54
29.07.2012 19:20:04;21.7;53
29.07.2012 19:25:04;21.7;53
(Date, time, temperature, humidity) in the following style (cropped at the top):
The labels on the x axis are the hour from the time of day and below are the weekdays and the date. I don't have the weekdays in my data file, but I'd like to have the date below the hours.
My plotfile:
set datafile separator ";"
set terminal png size 5280,1024
set output '~/tfd.png'
set xdata time
set timefmt "%d.%m.%Y %H:%M:%S"
set format x "%H"
plot "data.csv" using 1:2 title 'temperatur'
I can think of three method to do this. If you don't have to have those dates on the same axis, the second method is probably the most stable. Both the first and third methods have their advantages and disadvantages. Between those two, the third is possibly the better approach, but it requires more work.
For these examples, in order to make sure that the data would span more than 1 day, I used your same data but added one extra line
31.07.2012 19:30:04;22.7;53
All three methods work with version 5.0.
Method 1 does not line up correctly in version 4.6, but can be made to with one extra command.
Method 2 should work in any reasonably recent version.
Method 3 will not place all date labels in version 4.6 due to an overflow bug in iteration (see here for some explanation), but can be made to work by changing the iteration to place the labels.
Method 1 - Multiplot
We can do this by superimposing the same plot over itself using multiplot and doing the x-axis different each time.
set datafile separator ";"
set xdata time
set timefmt "%d.%m.%Y %H:%M:%S"
# Increase bottom margin to allow room for dates
set bmargin at screen 0.1
set multiplot layout 1,1
# tics starting at 0 every 6 hours showing hour
set xtics 0,60*60*6 format "%H"
plot "data.csv" using 1:2 with lines t "Temperature"
# Tics starting at 0 every 24 hours showing day.month
# moved down by 1 character to be under hours
set xtics 0,60*60*24 format "%d.%m" offset 0,-1
set origin 0,0 # This is not needed in version 5.0
replot
unset multiplot
Other than the difference in the axis labels, the plots must be identical to avoid them not lining up, and it does cause the y-axis labels to be slightly bolded as they are written over themselves.
In version 5.0 the set origin command is not needed, but is needed in version 4.6.
Method 2 - Secondary Axis
If using the secondary axis is acceptable, you could also approach it that way. For example, if the day is shown on the x2 axis and the hour on the x1 axis, we could do
set datafile separator ";"
set xdata time
set x2data time
set timefmt "%d.%m.%Y %H:%M:%S"
set xtics 0,60*60*6 format "%H"
set x2tics 0,60*60*24 format "%d.%m"
plot "data.csv" using 1:2 with lines t "Temperature"
This eliminates some of the problems of the multiplot method, but results in the two data labels being on different axes.
Method 3 - Setting Manual Labels
Finally we can manually set the labels. Fortunately, we can use a loop in the most recent version of gnuplot, so we don't have to issue a separate command for it, but we do have to compute the labels ourselves.
We can use the stats command to compute the labels. The stats command will complain if we give it time data, so we must use it before setting the time mode on, and we must do a little bit of work for computing the day boundaries. To make sure that we are working with the start of each day and not sometime in the middle, we parse the dates into an internal representation (seconds since the Unix Epoch), and round down to the nearest multiple of 86400 (the number of seconds in a day).
Altogether we can do
# in-large margin for date labels
set bmargin at screen 0.1
set datafile separator ";"
# Get first and last day in data file as STATS_min and STATS_max
stats "data.csv" u (floor(strptime("%d.%m.%Y %H:%M:%S",stringcolumn(1))/86400)*86400) nooutput
set xdata time
set timefmt "%d.%m.%Y %H:%M:%S"
set for [i=STATS_min:(STATS_max+86400):86400] label strftime("%d.%m",i) at i,graph 0 center offset 0,char -2
# set xtics every 6 hours
set xtics 0,60*60*6 format "%H"
plot "data.csv" using 1:2 with lines t "Temperature"
We can improve this by numbering the labels if we need to later remove them ((i-STATS_min)/86400+1 will number them 1, 2, 3, etc). Note that like the first method we needed to increase the margin size on the bottom. I added one extra day to the labels to cover the possible rounding up that gnuplot will do on the x-axis.
There is a bug dealing with iteration and integer overflow in version 4.6. To use this solution in 4.6, change
set for [i=STATS_min:(STATS_max+86400):86400] label strftime("%d.%m",i) at i,graph 0 center offset 0,char -2
to
days = (STATS_max-STATS_min)/86400+1
set for [i=0:days] label strftime("%d.%m",i*86400+STATS_min) at (i*86400+STATS_min),graph 0 center offset 0,char -2
I am trying to plot a simple graph, x and y coordinates, however how my axis labels are not quite as I wish.
How can I change the '1e+08' and so on to their true value, 100000000
How can I shift the labels of the xtics down so they don't obscure the graph?
Can I print the coordinates in the graph of certian points, for example the dip between 2014-05-10-04-00 and 2014-05-10-08-00?
How can one add more intervals in the labels of the x axis?
Here is the input I'm using:
reset
clear
set output "BytesOverTime.png"
set title "Evolution of Bytes over Time"
set ylabel 'Bytes'
set xlabel 'Time'
set key off
set term png
set xdata time
set timefmt "%Y-%m-%d-%H-%M"
set format x "%Y-%m-%d-%H-%M"
set xtics rotate by 90 nomirror
set datafile separator ' '
set logscale y
plot "timeBytesAverage.out" using 1:2
And the file if its needed to test:
http://pastebin.com/raw.php?i=qqpeJj4V
How can I change the '1e+08' and so on to their true value, 100000000
set format y "%f"
or, as this will give you decimal numbers:
set format y "%.0f"
You may also have a look at
set format y "%.0s%cByte"
which will create MByte, GByte, ... (See right y-axis in my plot)
However, this will be to the base of 1000, not 1024.
How can I shift the labels of the xtics down so they don't obscure the graph?
set xtics rotate by 90 nomirror right
will right-align (left-flush) the tic marks
Can I print the coordinates in the graph of certian points, for example the dip between 2014-05-10-04-00 and 2014-05-10-08-00?
If you know the coordinates, yes:
set xtics add ("high" "2014-05-09-23-30", "low" "2014-05-10-22-30" )
The general syntax is:
set xtics add ( <label1> <position1>, <label2> <position2> , ...)
This will add the list of labels to the automatically generated labels. If you omit the word add, there will be no automatically generated labels, just those in your list.
How can one add more intervals in the labels of the x axis?
set xtics 3600
will generate a label every 3600 seconds, i.e. every hour. This does not work for log scale axes.
set mxtics 2
will cause the gap between two major (labeled) tics being divided into two smaller gaps, i.e. one minor tic mark between two major ones. (However, it seems not to be necessary here, as gnuplot decides to use 2 on it's own)
And here is the result:
Note that I also added
set y2tics
set y2range[1E8:1E12]
set format y2 "%.0s%cByte"
set logscale y2
to demonstrate this special format on the right y-axis.
And by the way: The format of the labels on the y-axis is independent from the format in the data file.
set timefmt "%Y-%m-%d-%H-%M" defines the format inside the file
set format x "%Y-%m-%d-%H-%M defines the format in the plot. So ou may do something like set format x "%Y-%m-%d %H:%M which is more readable.
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 ^^).