2

So, I've got next problem. I'm writing a Perl plugin for my own Gnuplot wrapper, and I need to plot stacked-area chart, but here's problem with tics.

I have the following datfile (date in epoch - for Perl functions):

date    c1  c2  c3  c4  c5  c6  c7  c8  c9  c10 c11 c12
1521230521  173 830 988 284 165 577 920 749 409 705 703 601
1521316921  501 691 883 573 325 152 499 526 417 708 259 587
1521403321  33  193 576 106 397 329 801 857 534 559 527 213
1521489721  827 186 910 412 688 650 13  201 222 150 468 353
1521576121  53  425 726 989 362 489 554 986 480 485 414 74
.....

And I got this script (used variables from Perl script, keep note of this):

reset
set encoding utf8

set term pngcairo size $w, $h
set datafile separator "\\t"

set key autotitle
set key reverse Left outside
set key samplen 0.25 spacing 1 font "Roboto Mono Medium, 11"
set key bot center horiz
set key height 1

set output "img.png"

set xtics ("16 mar 22:45" 0, ...., "04 apr 22:45" 19) # string generated by perl
set xtics font "Roboto Mono Light, 9" nomirror out 
set ytics font "Roboto Mono Light, 9" nomirror out

set auto y
set tics front

# $rm # set rmargin
# $lm # set lmargin

set grid xtics ytics front
set style data filledcurves x1
set pointsize 0.8

plot for [i=2:".($cols+1).":1] '$datfile' using 1:(sum [col=i:".($cols+1)."] column(col)) title columnheader(i)

I need tics to look like that:

enter image description here

but tics don't show up:

enter image description here

You might ask me why I am not using set xdata time? That's because of uncontrollable tic overlapping in case if there's a lot of tics. That's why I'm using strict pre-calculated pairs like this:

set xtics ("16 mar 22:45" 0, "22 mar 23:02" 6, ...., "04 apr 22:45" 19)

and that worked for the histogram chart.

What am I doing wrong?

Community
  • 1
  • 1
genesi5
  • 455
  • 3
  • 17

1 Answers1

0

Your tics are out of range. The real values on the x-axis are taken from the column 1, they start at 1521230521, not 0.

Generate your tics with the correct "pos" values:

set xtics ("16 mar 22:45" 1521230521, \
           "17 mar 22:45" 1521316921, \
choroba
  • 231,213
  • 25
  • 204
  • 289
  • no, it's not how it suppposed to be. The xtics with 0 to 19 represents the number of rows in datafile (excluding first one), as well as its position on x-axis. First column is used by perl for timeformating them in the way i need. – genesi5 Mar 16 '18 at 18:45
  • 2
    @genesi5 Then you must also use the row number for plotting `plot ... using 0:(sum ...)` – Christoph Mar 16 '18 at 19:43