1

I am trying to use gnuplot to fill between a curve and the x axis for a certain xrange. For example I would like to fill between the line f(x)=x when x<5.

Example code:

set xrange [-10:10]
set yrange [-10:10]
set samples 100
plot x with filledcurves above x1=5

When this is plotted in Gnuplot 5.0 it does not show any fill.

I can try the reverse of:

plot x with filledcurves below x1=5

This gets closer because it fills below the line f(x)=x when x<5, however, it also shades the area above when x>5. There is also no way to limit it to above the x axis as well.

Any assistance would be appreciated. Thanks.

Epic_Test
  • 71
  • 3

1 Answers1

0

It seems there is no "direct" way to do it. Christoph gives a solution here.

Based on his code I came up with the following:

set xrange [-10:10]
set yrange [-10:10]

filter_lt(x,xmax) = ((x < xmax) ? x : 1/0)
f(x) = x
xmax = 5

plot '+' using (filter_lt($1,xmax)):(f($1)) with filledcurves x1 lt 1 notitle,\
     '' using 1:(f($1)) with lines lw 2 lt 1 title 'f(x)=x'
Community
  • 1
  • 1
bambino350
  • 182
  • 9