2

There is a style to fill the space between two functions of x. Examples of such plots can be found e.g. at http://gnuplot.sourceforge.net/demo/fillbetween.html Is there any way to make similar plot, but with flipped x and y axes? Here is the desired shape of a curve (without rotated/mirrored labels, titles and legends, of course)...

Approximate desired look

It could be done with closed contour (like last example here http://www.gnuplot.info/demo_svg_cvs/fillcrvs.html), but this would require reshuffling the data file. Any other options?

Thank you!

Roux
  • 383
  • 1
  • 10
  • Technically, the drawing above is no longer a function of x. Are you actually plotting functions or are you plotting from data files? It also helps if you include code that is close to what you want. Functions are harder, you need to invert your functions. Data files would be easier. Look into actually rotating the tic marks and place the 'title' as a rotated label. Legend is tougher. But with what you have above, have a blank title (title "") in the plot command. If you need a legend, [check this out](https://stackoverflow.com/questions/39334702/gnuplot-rotate-key). – Dan Sp. Jun 04 '18 at 15:02
  • Thank you! I try to plot a datafile. Probably, it is indeed easier to use filledcurves closed and tweaked data file... – Roux Jun 08 '18 at 07:07

2 Answers2

2

You can't do this directly. From help filledcurves:

The third variant fills the area between two curves sampled at the same set of x coordinates. It requires three columns of input data (x, y1, y2).

I don't think you can specify (y, x1, x2) directly. As a workaround you can the area between the y axis and the larger function in some color, and then fill the area between the y axis and the smaller function in white:

x1(y) = cos(y)+1
x2(y) = cos(y)+2
xmax(y) = (x1(y) > x2(y) ? x1(y) : x2(y))
xmin(y) = (x1(y) < x2(y) ? x1(y) : x2(y))

plot '+' using (xmax($1)):1 with filledcurve y1, \
     '+' using (xmin($1)):1 with filledcurve y1 fillcolor rgb "white"

enter image description here

This probably has to be tweaked a little if one or both of the two functions can be negative.

user8153
  • 3,839
  • 1
  • 8
  • 18
  • Thanks! Nice tweak! In my case, it is even simpler, since individual lines are percentiles.. – Roux Jun 08 '18 at 07:15
1

With gnuplot >=5.2 it could be tweaked even further because it allows arrays. The following code shows a workaround how filled curves between vertically oriented curves can be realized. You can even use transparency. If you download the attached PNG you will notice that it actually has a transparent background. The basic idea behind this workaround is to make closed areas and fill them. For this, you need to reverse one border, concatenate the borders and plot them filled. Unfortunately, gnuplot has no function to reverse datapoints in a column, so you have to do it in a special procedure yourself.

The code:

### "Vertical" filledcurves
reset session

# create some dummy data
N = 50
set samples N
set xrange [-5:5]
set table $Data
    plot '+' u (sin($1)):1:(rand(0)*0.3+1) with table
unset table

# put Borders into arrays
stats $Data nooutput
RowCount = STATS_records
array BorderX1[RowCount]
array BorderX2[RowCount]
array BorderY[RowCount]
set table $Dummy
    plot $Data u (BorderX1[$0+1]=$1-$3):(BorderX2[$0+1]=$1+$3):(BorderY[$0+1]=$2) with table
unset table

# reverse BorderX2 and merge borders
set samples RowCount
set table $Border
    plot '+' u (BorderX1[$0+1]):(BorderY[$0+1]) with table
    plot '+' u (BorderX2[RowCount-$0]):(BorderY[RowCount-$0]) with table
unset table

# make the plot
set object 1 rect at 0,-3 size 10,0.5 fs solid 1.0 fc rgb "black" back
set yrange[-5:5]
plot \
    $Border u 1:2 w filledcurves fc rgb "#AA00FF00" not,\
    $Border u ($1*1.5):2 w filledcurves fc rgb "#AAFFFF00" not,\
    $Data u ($1+2.5):2 w filledcurves y2 fc rgb "brown" not,\
    $Data u 1:2 w l lw 8 lc rgb "blue" not,\
    '+' u 1:(cos($1)-0.5):(cos($1)+0.5) w filledcurves lc rgb "grey" not,\
    '+' u 1:(cos($1)):(1) w l lw 3 dt 2 lc rgb "white" not
### end of code

The result:

enter image description here

theozh
  • 17,412
  • 3
  • 21
  • 55