1

Drawing a step plot leads always to an out of border result.
How to solve the issue? Any ideas? THX!

The MWE is:

reset;set term png small size 500,500;set output 'test.png';
set title 'First step is always drawn out of chart borders ?!?';
unset y2tics;set y2range [0:40];set y2tics 10;set yrange [0:40];set ytics 10 mirror;
set style fill solid 1.00 border;
plot 'test.data' using 1:2  notitle with fillsteps lc rgb 'light-goldenrod', \
'' using 1:3 notitle with fillsteps lc rgb 'gray40', \
'' using 1:4 notitle with fillsteps lc rgb 'web-green', \
'' using 1:5 notitle with fillsteps lc rgb 'light-green';

The result is:

enter image description here

Used software is:

GNUPLOT Version 5.2 patchlevel 8

onemorequestion
  • 1,056
  • 1
  • 10
  • 15
  • Well, your "MWE" is not complete. How should we test if we don't see how your data looks like? – theozh Apr 18 '21 at 13:33
  • Take these for example ```echo -e "1 50 35 30 5/n2 55 30 20 5/n17 51 44 30 12/n20 1 1 1 1" > test.data``` or any you like where the second column values are greater than 40 which is the border value. – onemorequestion Apr 18 '21 at 14:46
  • If this is the data you want to plot... the first value in the second column is 50. So 50 is larger then your max xrange of 40. What do you expect? Clipping at the border of the graph? – theozh Apr 18 '21 at 16:15
  • Right. Absolutely. Like all the other values which are also greater than 40 in the y range respect but inside the borders. My question is why the first datapoint is drawn above the max y axis value and so out of the chart borders. – onemorequestion Apr 18 '21 at 16:58

1 Answers1

1

Ok, now I see your point. Looks like a little bug (or our limited understanding). I cannot tell right away why this is, but you can avoid it by adding a line in the beginning which contains the first x value and all y-values are 0. If you don't want to do this manually, there would be ways to do this automatically with gnuplot. But I hope there is a simpler solution.

Code:

### plot with fillsteps
reset session

$Data <<EOD
1    0   0   0   0
1   50  35  30   5
2   55  30  20   5
17  51  44  30  12
20   1   1   1   1
EOD

unset y2tics;set y2range [0:40]
set y2tics 10
set yrange [0:40]
set ytics 10 mirror
set style fill solid 1.00 border
unset key

plot $Data u 1:2 w fillsteps lc 'light-goldenrod', \
        '' u 1:3 w fillsteps lc 'gray40', \
        '' u 1:4 w fillsteps lc 'web-green', \
        '' u 1:5 w fillsteps lc 'light-green'
### end of code

Result:

enter image description here

Addition: (automatically duplicate first line, to workaround the bug(!?))

In order to workaround this (what I would call unexpected or a bug) you want to duplicate the first line automatically. There would be certainly different easy ways with external tools, however, which would not guarantee platform-independence. So, here is one of several possible gnuplot-only solutions.

  1. get your file into a datablock (here: $Data) (see gnuplot: load datafile 1:1 into datablock)
  2. print the first line of $Data into a new datablock (here: $Data2) Make sure that the first line is not a header or commented line, i.e. print the first dataline.
  3. append the full datablock $Data again to $Data2.

Data: (Test.dat)

1   50  35  30   5
2   55  30  20   5
17  51  44  30  12
20   1   1   1   1

Code: (Result same as above)

# https://stackoverflow.com/a/67151340/7295599
### plot with filledcurves
reset session

FileToDatablock(f,d) = GPVAL_SYSNAME[1:7] eq "Windows" ? \
                       sprintf('< echo   %s ^<^<EOD  & type "%s"',d,f) : \
                       sprintf('< echo "\%s   <<EOD" & cat  "%s"',d,f)     # Linux/MacOS

FILE = 'Test.dat'
load FileToDatablock(FILE,'$Data')

set print $Data2
    print $Data[1]   # only first line
    print $Data
set print

unset y2tics;set y2range [0:40]
set y2tics 10
set yrange [0:40]
set ytics 10 mirror
set style fill solid 1.00 border
unset key

plot $Data2 u 1:2 every ::0::0 w fillsteps lc 'light-goldenrod', \
        '' u 1:2 w fillsteps lc 'light-goldenrod', \
        '' u 1:3 w fillsteps lc 'gray40', \
        '' u 1:4 w fillsteps lc 'web-green', \
        '' u 1:5 w fillsteps lc 'light-green'
### end of code
theozh
  • 22,244
  • 5
  • 28
  • 72
  • well, or duplication the first data line seems to work as well. Seems like an initialization issue. – theozh Apr 18 '21 at 18:01
  • THX for answering! Could you add the gnuplot code for automatically solving this issue please. – onemorequestion Apr 18 '21 at 20:53
  • THX for showing a gnuplot only solution. I learned something new. THX. I'm really happy about gnuplot and it's powerfullness. To contribute to make it a little better would you fill in a bug report? Or should I do. I see you are a lot more experienced and maybe did this already and be a lot faster than me, so I would prefer you ;) – onemorequestion Apr 19 '21 at 08:31
  • After testing the solution, repeating the first line, I have to say that in my case this doesnt work, maybe due to the use of time setted xdata. But adding the first line with 0 for the y values works fine. – onemorequestion Apr 19 '21 at 11:28
  • @onemorequestion what does "doesn't work" mean? What's the result or the error message? You didn't mention in your question that you have time data, but this shouldn't play a role. If I see your _real_ (relevant) code, I can probably tell you what's going (wr)on(g). – theozh Apr 19 '21 at 17:21
  • If I copy the first line, the result is the same, the first step is drawn above y axis max value (out of chart borders). If I copy the timestamp and add zero y values all works fine. But for the data manipulation I use a oneliner system tool command. Your solution is correct and your answer remains accepted. Would you report the bug or should I do? THX. – onemorequestion Apr 19 '21 at 19:48
  • @onemorequestion I can do a bug report later this week. I still would be interested in how your actual data lines (with timestamp) look like. It's not (yet) clear to me why duplicating the first line should not work with timestamp whereas putting y-values to 0 seems to work. – theozh Apr 20 '21 at 12:37
  • It is strange. Using the MWE from above, you are right, it doesnt matter if x axis are in time modus or not, copying first line or adding a zero-line for the y values, both are working. However in my real case scenario it is NOT so. I took all the additional settings, which are in fact multiplot, style options, colorspace, key settings and so on but nothing special. I have no clue what leads to this behaviour. But the zero-methode is working fine, so I stop here. THX for your help. I really appreciate that. – onemorequestion Apr 21 '21 at 11:54
  • @onemorequestion bug report filed. https://sourceforge.net/p/gnuplot/bugs/2439/ let's see what the developers will say. – theozh Apr 21 '21 at 18:30
  • TOP! THX a lot @theozh. – onemorequestion Apr 21 '21 at 19:16
  • @onemorequestion it seems to be already fixed and probably available in one of the next gnuplot versions. Thanks to Ethan Merritt. – theozh Apr 27 '21 at 18:43
  • Good news. Gnuplot rocks. Thx for your solution and initiating the fix. – onemorequestion Apr 27 '21 at 19:40