Line is not shown in the diagram using gnuplot - date

I am trying to plot a diagram using gnuplot. I want to put the hours of the day in the x-axis. I managed to do that with the following code:
set term postscript eps enhanced color "Times" 24
set output "DailyAvailability.eps"
set xtics rotate by -45 font ",18"
set xdata time
set timefmt '%Y-%m-%d %H'
set format x '%H:%M'
set ylabel "Number of peers"
set xlabel "Time of the day [in hours]"
set yrange [0:30]
set xrange ['2015-12-30 15:50':'2015-12-30 16:00']
set key right top #FFA500"
plot "intervals.dat" using 1:2 lc rgb "#000077" t "availability" w lines
This is my input data
"2015-12-30 15:59" 6
"2015-12-30 15:58" 10
"2015-12-30 15:57" 17
"2015-12-30 15:56" 18
"2015-12-30 15:55" 19
"2015-12-30 15:54" 20
"2015-12-30 15:53" 18
"2015-12-30 15:52" 28
"2015-12-30 15:51" 23
After executing the code, I get the diagram but with no line drawn in it. I tried to read other questions, but I cannot see any major differences between their code and mine Gnuplot date/time in x axis. I also checked for blank spaces in the input file, but since there is no error or warning messages, I cannot figure out what is going on. Can anybody see what I am missing here? Thanks for your time!

There are two tiny mistakes that make gnuplot say
Skipping data file with no valid points
Your time format is missing the minutes %M. Hence %H should be %H:%M
The quotation marks which are part of your time format are missing.
The solution is supposed to look like this
set timefmt '"%Y-%m-%d %H:%M"'
Then, I get

Related

Date/Time Axes In gnuplot

I'm unable to get date/time to work in gnuplot. Here's what seems right to me, errors described below.
set xdata time
set timefmt "%Y-%j/%H:%M:%S"
#set xrange ["2016-349/00:56:00":"2016-349/00:57:00"]
set format x "%H:%M:%S"
plot "-" using ($1):($2) with lines
2016-349/00:56:26.560000 0.587785252292582
2016-349/00:56:27.560000 1.59702608337727e-13
2016-349/00:56:28.560000 -0.587785252292324
e
pause mouse any
With set xrange commented out as shown, I get this warning.
Warning: empty x range [2016:2016], adjusting to [1995.84:2036.16]
and the x-axis doesn't appear to be based on the range of the data, with ticks from 00:33:15 to 00:34:00. The resulting plot is a vertical line at 00:33:36, but the points are part of a sine wave.
Uncommenting set xrange, I get this error instead.
line 6: all points y value undefined!
I get the same behavior with gnuplot 4.2 patchlevel 6, and 5.0 patchlevel 1. Thanks for any help you can provide.
Jim
The error is here:
plot "-" using ($1):($2) with lines
You can use $ only in expressions, otherwise just use numbers itself:
plot "-" using 1:2 with lines

gnuplot - draw stacked line chart

I work with in-house benchmark tool. I use gnuplot (gnuplot 4.6 patchlevel 4) for visualization.
I need to represent results (method execution times for several runs) as stacked line chart, something like this:
Here is an excerpt from my .tsv data file:
Run MethodA MethodB MethodC
1 192 171 152
2 227 178 161
...
10 229 161 149
And the script I'm using:
#!/usr/bin/gnuplot -p
reset
clear
set terminal png size 640,480
set output "timings.png"
set key top left outside horizontal autotitle columnhead
set title "Third-party REST calls"
set xlabel "Run (ordinal)"
set xtics nomirror scale 0
set ylabel "Time (milliseconds)"
set ytics out nomirror
set grid ytics lt 0 lw 1 lc rgb "#bbbbbb"
set style data histogram
set style histogram rowstacked
set style fill solid border -1
set boxwidth 0.75
plot "timings.tsv" using 2:xticlabels(1) , "" using 3, "" using 4
I get the following result:
Yes, it's not a line chart but histogram (I need to represent percentage of execution time of each method). I need slightly different result (the same histogram, not with boxes but with lines which connect boxes tops and with filling below lines), like this:
I'm aware of approach with filledcurve's (for instance, described there Creating a Filled Stack Graph in GNUPlot), but in that approach you need to sum values explicitly.
Is it possible to draw filled areas instead of boxes via gnuplot, e.g. convert histogram into stacked line chart?
You do need to sum values explicitly, but this is not a big issue. You can script it easily:
firstcol=2
cumulated(i)=((i>firstcol)?column(i)+cumulated(i-1):(i==firstcol)?column(i):1/0)
plot "file.dat" using 1:(cumulated(4)), "" using 1:(cumulated(3)), "" using 1:(cumulated(2))

how to plot arrow on date xaxis?

I have plot that has dates for xaxis. The format is
set xdata time
set timefmt x "%Y%m%dT%H%M%S"
The actual data file has "date" only timestamps - i.e. not the following T part BUT plots correctly.
20130601
When I want to plot a vertical arrow I get no error - but no arrow either:
set arrow from 20130601,0 to 20130601,500000
When using time formats, the respective parts of the data file are read in as string. So for the arrow you must use
set arrow from "20130601",graph 0 to "20130601",graph 1
If you use integers, then they are interpreted as Unix timestamps, and 20130601 corresponds the the 21. August 1970. So you don't get an error, but the date is not in your range.

gnuplot reading from data to plot bar chars

I have a file with two columns
9 5
10 3
11 0
12 25
13 50
14 80
etc
What is the best way to plot bar char using gnuplot? Is using subprocess with gnuplot the best way? Ideally the graph should be in .pdf and in png as I want to put these on a website later on.
I would really appreciate your input/advise.
Here is an example, how to plot a bar chart with gnuplot using the plotting style with boxes
set terminal pngcairo size 1000,800 font ',12'
set output 'output.png'
set xlabel 'xlabel' font ',18'
set ylabel 'ylabel' font ',18'
set boxwidth 0.9
set style fill solid 0.3
set offset 0.5, 0.5, 10, 0
plot 'data.txt' with boxes linewidth 3 title ''
With the data you showed, this gives the following output image:

translate matlab plot to gnuplot 3d

I have a matrix of fft data over time, 8192 rows of data x 600 columns of time. The first column is a frequency label, the first row is shown below but doesn't actually exist in the data file, neither do the spaces, they are shown just for ease of reading.
Frequency, Sec1, Sec2, Sec3...Sec600
1e8, -95, -90, -92
1.1e8, -100, -101, -103
...
It is plotted in matlab with the following code (Apologies to other posters, I grabbed the wrong matlab code)
x is a matrix of 8192 rows by 600 columns, f is an array of frequency labels, FrameLength = 1, figN = 3
function [] = TimeFreq(x,f,FrameLength,figN)
[t,fftSize] = size(x);
t = (1:1:t) * FrameLength;
figure(figN);
mesh(f,t,x)
xlabel('Frequency, Hz')
ylabel('time, sec')
zlabel('Power, dBm')
title('Time-Freq Representation')
I cant quite figure out how to make it work in gnuplot. Here is a sample image of what it looks like in Matlab: http://imagebin.org/253633
To make this work in gnuplot, you'll want to take a look at the splot (for "surface plot") command. You can probably figure out quite a lot about it just by running the following commands in your terminal:
$ gnuplot
gnuplot> help splot
Specifically, you want to read the help page shown by running (after the above, when the prompt asks for a subtopic): datafile. That should tell you enough to get you started.
Also, the answers to this question might be helpful.
so here is the gnuplot command script that I ended up using. It has some additional elements in it that weren't in the original matlab plot but all the essentials are there.
set term png size 1900,1080
set datafile separator ","
set pm3d
# reverse our records so that time moves away from our perspective of the chart
set xrange[*:*] reverse
# hide parts of the chart that would make the 3d view look funny
set hidden3d
# slightly roate our perspective and compress the z axis
set view 45,75,,0.85
set palette defined (-120 "yellow", -70 "red", -30 "blue")
set grid x y z
set xlabel "time (secs)"
set ylabel "frequency"
set zlabel "dBm"
# plot all the data
set output waterfall.png
splot 'waterfall.csv' nonuniform matrix using 1:2:3 with pm3d lc palette