0

basically I would like to reproduce the filling styles in the following image in gnuplot: enter image description here

I tried using the common pattern with filledcurves but none of the patterns is similar to those in the picture. Is there a way to get this type of patterns (note the filled area is not solid) in gnuplot ? Thank you.

theozh
  • 22,244
  • 5
  • 28
  • 72
RIXS
  • 115
  • 5
  • 1
    Could you please post your data and your code? What have you tried so far? https://stackoverflow.com/help/minimal-reproducible-example – theozh Jan 29 '21 at 21:36
  • My guess would be that this might be rather difficult in gnuplot. gnuplot has a limited number of hatch patterns (see https://stackoverflow.com/q/53547501/7295599). As far as I know, **vertical** _and_ **dashed** lines are not in the gnuplot repertoire. A cumbersome solution to extend this a bit, see here: https://stackoverflow.com/a/63471784/7295599 – theozh Jan 30 '21 at 17:06

1 Answers1

1

Check help filledcurves and set the color to transparent according to the scheme 0xAARRGGBB.

Code:

### semitransparent fill between curves
reset session

# create some random test data
set print $Data1
    do for [x=1:100] { print sprintf("%g %g %g %g",x,5*cos(x/7.)+rand(0),rand(0)+0.3,rand(0)+0.3) }
set print
set print $Data2
    do for [x=1:100] { print sprintf("%g %g %g %g",x,3*sin(x/9.)+rand(0),rand(0)+0.3,rand(0)+0.3) }
set print
unset key

plot $Data1 u 1:2 w l lc "red", \
     ''    u 1:($2-$3):($2+$4) w filledcurve lc rgb 0xeeff0000, \
     $Data2 u 1:2 w l lc "blue", \
     ''    u 1:($2-$3):($2+$4) w filledcurve lc rgb 0xee0000ff
### end of code

Result:

enter image description here

Addition: (workaround for vertical dashed "fill")

To be honest, (as in your case) if you have to zoom in very close to see the difference between a semitransparent fill and a "fill" with vertical lines, then I'm not sure whether this is really necessary.

Anyway, here is a workaround for a "fill" of vertical dashed lines. This is realized with vectors and dashed lines dt 1 (=solid), dt 2 (=dashed), dt 3 (=dotted). However, this is not a real fill but requires enough regular (here: 1000) data points to give this impression. It also depends on transparency of the linecolor and the size of the graph. If you don't have enough regular datapoints you could resample your data, however, this is not straightforward in gnuplot (see: Resampling data with gnuplot),

This still doesn't look identical to your example but comes somewhat closer.

Code:

### special "fill" with dashed vertical lines
reset session

# create some random test data
set table $Data1
    set samples 1000
    plot [1:100] '+' u (x):(3*cos(x/5.)):(rand(0)*0.5+0.3):(rand(0)*0.5+0.3) w table
set table $Data2
    set samples 1000
    plot [1:100] '+' u (x):(5*sin(x/7.)):(rand(0)*0.5+0.3):(rand(0)*0.5+0.3) w table
set table $Data3
    set samples 1000
    plot [1:100] '+' u (x):(7*sin(x/9.)):(rand(0)*0.5+0.3):(rand(0)*0.5+0.3) w table
unset table

unset key
plot $Data1 u 1:2 w l lc "red", \
     ''    u 1:($2-$3):(0):(1) w vectors lc rgb 0xddff0000 dt 1 nohead, \
     $Data2 u 1:2 w l lc "green", \
     ''    u 1:($2-$3):(0):($4+$3) w vectors lc rgb 0xdd00ff00 dt 2 nohead, \
     $Data3 u 1:2 w l lc "blue", \
     ''    u 1:($2-$3):(0):($4+$3) w vectors lc rgb 0xdd0000ff dt 3 nohead 
### end of code

Result:

enter image description here

Zoomed-in to show the dashed lines:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72
  • Thank you for the answer, but I would like to create the filling patterns like the ones in the figure, not a simple solid pattern. – Andrea Jan 30 '21 at 16:47
  • Then please provide some data and a clear description or sketch and ideally your gnuplot code which "doesn't work"! Otherwise it will be tedious to help! – theozh Jan 30 '21 at 16:52
  • Ok, now I see. If you zoom in into the image, the "fill color" constists out of tiny lines. Please mention such **_important_** details in the question! StackOverflow is not a platform for questions like: "I want this! How do I do this?" see https://stackoverflow.com/help/how-to-ask – theozh Jan 30 '21 at 17:08