configure gnuplot to handle timeseries like excel - linux

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!

Related

set xtics by <start>, <incr> in gnuplot does not work

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.

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?

Offset gnuplot grid lines so that they match xtics

How do I move the vertical grid lines so that they match the horizontal labels/xtics?
In the following image, the vertical grid lines don't line up with the xtics:
I tried setting the xtics offset before setting the grid, but that doesn't seem to work.Here's my current script:
#!/usr/bin/gnuplot -persist
set terminal png nocrop font small size 40000,800
set output 'decode3.png'
set style data linespoints
set title "Raw Audio Chunk"
set xlabel "Count"
set ylabel "Sample Value"
set xtics 16 offset 10
set ytics 10000
set grid
plot "decode3_Samsung_Exhibit.csv"
Thats the wrong way of thinking about this! The offset parameter only shifts the xtics labels (in your case by 10 character widths), but the xtics remain at their original positions. And the grid lines are drawn at the tic positions.
What you probably want is to shift the data a bit to the right. That is done by shifting the actual x-values to the right like
set xtics 16
set grid
plot "decode3_Samsung_Exhibit.csv" using ($1 + 10):2
That assumes, that your data file has two columns. The x-values are shifted by 10 (in units of the x-axis) to the right.

gnuplot value on Y-axis

I have a file which contains two column data. when plotted, it looks like
Green line is showing mean.
I want to show mean value on Y-axis. Is it possible?
code:
set style data lines
set termoption enhanced
set term png
set title "17th oct"
stats 'data/17-10-2013' using 1:2 nooutput
set xdata time
set timefmt "%s"
set format x "%H"
set output "images/17_DB.png"
plot "data/17-10-2013" using 1:3 title " Data" , STATS_mean_y title " Mean"
Here are three different options to display the value:
set term pngcairo enhanced
set output "images/17_DB.png"
set title "17th oct"
stats 'data/17-10-2013' using 1:2 nooutput
set xdata time
set timefmt "%s"
set format x "%H"
# first option
set ytics add (sprintf('%.1f', STATS_mean_y) STATS_mean_y)
# second option
set ytics add ('' STATS_mean_y)
set rmargin 3
set label left at graph 1.05,first STATS_mean_y sprintf('%.1f', STATS_mean_y)
set style data lines
# third option inside the key label
plot "data/17-10-2013" using 1:3 title "Data" , \
STATS_mean_y title sprintf("Mean = %.1f", STATS_mean_y)
Here some notes about the different options:
The first option is the easiest, but the label could overlap with another label (here with the 0).
The second option adds an empty mayor tic, and places the label on the right side. This requires the right margin to be increased manually (you may need to use another value, e.g. set rmargin 2 and other coordinates).
The third option just places the value in the key (legend) entry.
For a nicer x-axis, you may want to add set autoscale xfix, which gets you rid of the empty space on the right side.

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