Gnuplot error in ploting histogram with xdate - gnuplot

I'm trying to plot a histogram with the xtics as time information. The gp script I'm using is this one:
set style data histogram
set style histogram cluster gap 1
set boxwidth 1
set datafile separator "\t"
set yrange[0:3000]
set xlabel "xaxis"
set ylabel "yaxis"
set xdata time
set timefmt "%Y-%m-%d %H"
set terminal png size 1200,800
set output outputfile
plot inputfile u 2:1 title "Count"
An example of my inputfile(that I pass by parameter) is this one:
2012-07-22 00:00:00 159.361111111
2012-07-22 01:00:00 207.019166667
2012-07-22 02:00:00 191.749722222
2012-07-22 03:00:00 147.647777778
2012-07-22 04:00:00 107.751388889
2012-07-22 05:00:00 95.9566666667
2012-07-22 06:00:00 110.405277778
2012-07-22 07:00:00 151.689166667
2012-07-22 08:00:00 244.787777778
2012-07-22 09:00:00 481.601388889
However I'm receiving the error "plot_timeflow.gp", line 16: Too many columns in using specification and when I try to set the plot command to plot inputfile u 2:xticlabels(1) title "Count" I have the following error: "plot_timeflow.gp", line 16: Need full using spec for x time data.
Does someone have any ideia, what is the problem??
Thanks in advance.

Strange indeed. But in any case, for your data the boxes plotting style is better, because with histograms, every box has an own xtic. With boxes, the x-axis is treated as a normal time axis:
set boxwidth 0.8 relative
set datafile separator "\t"
set yrange[0:3000]
set xlabel "xaxis"
set ylabel "yaxis"
set xdata time
set timefmt "%Y-%m-%d %H"
set style fill solid
plot 'data.txt' using 1:2 with boxes title "Count"
That gives:

Related

Controling the frequency of x2tics in gnuplot in

I am trying to plot a data file similar to the sample given below albeit much bigger.
1.0 12.0 0.03
2.0 14 0.586
10.0 16 0.798
50.0 18 1.023
250.0 28.9 1.124
1000.0 30.2 1.456
I want to plot column 1 with 3 while column 2 will be my upper axis ticks. The code the given below:
reset
set logscale x
set logscale y
set xtics nomirror
set xtics (1 ,100, 1000)
set x2tics (1, 100, 1000)#(x2tics is not changing)
set autoscale xfix
set autoscale x2fix
set xlabel 'x'
set ylabel 'y'
set x2label 'm'
plot 'data_test.txt' using 1:3:x2tic(2) with linespoints ps 2 lw 2 title 'y wrt x'
The initial ticks are all overlapping and I want to reduce the ticks. However, changing x2tics is not fixing the issue. Kindly help.
You are missing a set logscale x2.
Full code:
reset
set logscale x
set logscale y
set logscale x2
set xtics nomirror
set xtics (1 ,100, 1000)
# The next line would plot a confusing 100 between 18 and 28.9,
# so I commented it out
# set x2tics (1, 100, 1000)#(x2tics is not changing)
# But we have to enable x2tics
set x2tics
set autoscale xfix
set autoscale x2fix
set xlabel 'x'
set ylabel 'y'
set x2label 'm'
plot 'data_test.txt' using 1:3:x2tic(2) with linespoints ps 2 lw 2 title 'y wrt x'
The result:
Update
To reduce the number of x2tics, I would try two plots: The first plots the data points, the second one only plots the x2tics:
plot 'data_test.txt' using 1:3 with linespoints ps 2 lw 2 title 'y wrt x', \
'data_test.txt' using 1:(NaN):x2tic(2) every 2 notitle
Here, NaN "hides" the data points, and every 2 skips every 2nd line.

Gnuplot, how can I get hh:mm on x axis

With this datafile (x.txt)
20180522110000 6.03
20180522144500 10.44
20180523071501 5.17
and this command file (x.gnuplot)
set term png
set output "x.png"
set xdata time
set timefmt "%Y%m%d%H%M%S"
set format x "%H:%M"
plot "x.txt" using :2 w lines
and using gnuplot 5.0
I don't get the desired x-labels. I get only
00:00 00:00 00:00 00:00
not (something more like, give or take some details...)
11:00 .... 07:15
What am I doing wrong?
Solved it.
I was missing "1"
Wrong:
plot "x.txt" using :2 w lines
Correct:
plot "x.txt" using 1:2 w lines

Gnuplot date on x axis and missing data

I am trying to make a chart of data, which depends on time. I have this data:
01/1851 NaN 0.812 0.862 0.735 2.19
02/1851 NaN 1.739 1.733 1.695 1.875
03/1851 NaN 1.472 1.376 1.458 3.31
04/1851 NaN 1.847 1.775 1.828 6.06
05/1851 4.48 2.038 1.762 2.125 7.695
06/1851 10.06 0.347 0.276 0.383 5.48
07/1851 6.67 0.402 0.323 0.395 9.76
08/1851 3.21 1.57 1.469 1.421 8.62
09/1851 1.78 2.64 2.616 2.589 10.075
10/1851 3.7 1.269 1.314 1.137 4.295
11/1851 7.62 6.206 6.236 6.058 8.87
I need to make a chart of all this columns in one chart. Problem is, that date is monthly, and some values are NaN (not a number) which should not be ploted, but it says "all points y value undefined!" when i do this
set xdata time
gnuplot> set timefmt "%m/%y"
gnuplot> set xrange ["01/1851":"12/2014"]
gnuplot> set format x "%m/%y"
gnuplot> set timefmt "%m/%y"
gnuplot> plot "milesovka.txt" u 2:3
Can somebody help me? I tried this even ix excel, but i doesn't take dates before 1900.
Why do you specify u 2:3? You then wouldn't have a date on the x-axis.
This seems to work fine:
set xdata time
set timefmt "%m/%Y"
set format x "%m/%Y"
plot for [i=2:6] "milesovka.txt" u 1:i ti "Column ".i w lp

How to plot a large dataset with more than 800,000 samples using gnuplot

I have a dataset of 818,741 samples. values range between 0 and 7276. I am using the following gnuplot script to plot the data.
#+begin_src gnuplot :var data=xtics :exports code :file file.png
reset
set term png
set output "data.png"
set title "Variations/entity"
set xlabel "entity"
set xtics rotate by -45
set yrange [0:7276]
set ylabel "# fo variations"
plot 'sort_1.txt' u 2:xticlabels(1) w lp lw 2 notitle
#+end_src
Problem
The problem is that the cruve becomes a straight line when I use the dataset with the 818,741 samples.I cannot see the distribution of the data anymore. What plot do you suggest.
Sample data
entity # of variations
E0669803 7276
E0726485 496
E0679687 459
E0159288 395
E0018102 337
E0498282 333
E0349508 322
E0566375 315
E0096588 314
E0182788 313
E0595006 312
E0550909 291
E0338738 290
E0031352 290
E0409686 284
E0576457 279
E0277375 275
E0277379 0
update
The following script is for the whole dataset. Well I don't think I can do any better.
#+begin_src gnuplot :var data=xtics :exports code :file file.png
reset
set term png
set output "data.png"
set title "Variations/entity"
set xlabel "entity"
set xtics rotate by -90
set yrange [0:7276]
set ylabel "# fo variations"
plot 'data.txt' u 2:xticlabels(1) every 100000 w lp lw 2 notitle
#+end_src
If you want to extract statistical data from your data sample, try boxplots, one for each entity:
set yrange [0:7276]
set style fill solid 0.25 border -1
set style boxplot nooutliers pointtype 7 separation 2
set boxwidth 1
plot "data.txt" using (1.0):2:(0):1 with boxplot notitle
This creates one boxplot for all data samples with the same string value in the first column, your "entity". And one boxplot for each unique entity is generated.

mixing date and time on gnuplot xaxis

I'd like to plot hours of the day on the x axis, but print the date when the day rolls over from one day to the next. So the x axis might look like this:
11/02 04:00 08:00 12:00 16:00 20:00 11/03 04:00 08:00 ...
Is there a sane way to do this in gnuplot?
FWIW, my file currently looks something like this:
set xdata time
set timefmt "%Y-%m-%d|%H:%M:%S"
plot '-' using 1:2 with lines linewidth 1 linecolor rgb "#FF0000"
2013-11-02|00:00:48 123.0
2013-11-02|00:00:55 124.0
2013-11-02|00:01:06 121.0
2013-11-02:00:01:17 123.0
...
2013-11-04|23:59:41 241.0
2013-11-04|23:59:52 241.0
That is a tough one, made me think a bit. Here is how you can do it:
You need to set the format of the x-axis to %H:%M and then replace the 00:00 with dates, similarly like done in this answer.
The main work is then to extract the timestamps for the mid nights. I use the stats command for this (needs at least version 4.6.0), but because it doesn't support time data you must fiddle around a bit with strptime and similar:
fmt = "%Y-%m-%d|%H:%M:%S"
stats 'file.txt' using (strptime(fmt, stringcolumn(1))) nooutput
t = int(STATS_min)
t_start = t - tm_hour(t)*60*60 - tm_min(t)*60 - tm_sec(t)
num_days = 2 + (int(STATS_max) - t)/(24*60*60)
set xdata time
set timefmt fmt
set xtics 4*60*60
set for [i=1:num_days] xtics add (strftime('%m/%d', t_start+(i-1)*24*60*60) t_start+(i-1)*24*60*60)
set format x '%H:%M'
plot 'file.txt' using 1:2 with lines
I increment num_days by 2 to account for the possible automatic extension of the x-range to the next tics.
The result with your data is (with 4.6.4):
Here is a version with xticlabels:
$data <<EOD
2013-11-02|00:00:48 123.0
2013-11-02|00:00:55 124.0
2013-11-02|00:01:06 121.0
2013-11-02|00:01:17 123.0
2013-11-04|23:59:41 241.0
2013-11-04|23:59:52 241.0
EOD
set xdata time
set timefmt "%Y-%m-%d|%H:%M:%S"
plot $data using 1:2 w l # plot to get GPVAL_X_MIN GPVAL_X_MAX
t = GPVAL_X_MIN
t_start = t - tm_hour(t)*60*60 - tm_min(t)*60 - tm_sec(t)
num_days = 1 + (GPVAL_X_MAX-GPVAL_X_MIN)/(24*60*60)
replot [i=0:6*num_days:1] '+' us (t=t_start+i*24*60*60/6, strftime('%Y-%m-%d|%H:%M:%S', t)):(NaN):xtic(strftime(int(i)%6?'%H:%M':'%m-%d',t)) t ""
So the format is selected with int(i)%6?'%H:%M':'%m-%d'.
This was inspired by gnuplot: set link and x2tics in interactive mode.

Resources