As part of a larger project in which VBA creates worksheets using excel data and a word template I am learning gnuplot which VBA will also control.
I am trying to plot 2 functions in the same graph and shade a side. I would like for the function lines to be black or be able to specify. I would also like to specify whether the line is solid or dashed. I have sent a picture of the desired result produced through another program which is not open source so I can't control it. And I sent my best code yet. I am gratefu for any help.
I have searched the web and gnuplot documentation but nothing addresses this. `
reset session
set grid ls 100 lc black
set grid x,y back
set style fill transparent solid 0.1
set xzeroaxis linetype 3 linewidth 2.5
set yzeroaxis linetype 3 linewidth 2.5
set xrange [-10:10]
set yrange [-10:10]
f(x) = -2*x+7
g(x) = (0.6)*x-2
plot f(x) w filledcurves x1 lc "white", \
f(x) w filledcurves x2 lc "green", \
f(x) w l, \
g(x) w filledcurves x1 lc "yellow", \
g(x) w filledcurves x2 lc "white", \
g(x) w l
Desired result
Result
I tried the code sent above and made a lot of progress but still lacking the control over color and fill
Maybe I don't fully understand your problem.
If you want black dashed lines, simply specify it, e.g. w l lc "black" dt 2
.
What is the reason that you are filling with white, to avoid transparent background?
Script:
### semitransparent filledcurves and dashed lines
reset session
set grid ls 100 lc black
set grid x,y back
set style fill transparent solid 0.1
set xzeroaxis linetype 3 linewidth 2.5
set yzeroaxis linetype 3 linewidth 2.5
set xrange [-10:10]
set yrange [-10:10]
f(x) = -2*x+7
g(x) = (0.6)*x-2
plot f(x) w filledcurves x2 lc "green", \
f(x) w l lc "black" dt 2 lw 1.3, \
g(x) w filledcurves x1 lc "yellow", \
g(x) w l lc "black" dt 3 lw 1.3
### end of script
Result:
Addition: (pattern overlay)
Unfortunately, fill patterns in gnuplot are rather limited. You cannot freely define the angle, density or thickness of the hatch lines, unless you don't fear the one or the other complicated workaround. Furthermore, I don't know if there is a better way to set the background of a pattern fill other than to plot two filled areas on top of each other. However, then you will have the problem of the correct pattern/color in the legend. I guess this might be complicated to achieve (maybe with multiplots).
Script:
### semitransparent filledcurves with patterns
reset session
set grid ls 100 lc black
set grid x,y back
set style fill transparent solid 0.1
set xzeroaxis linetype 3 linewidth 2.5
set yzeroaxis linetype 3 linewidth 2.5
set xrange [-10:10]
set yrange [-10:10]
set key out
f(x) = -2*x+7
g(x) = (0.6)*x-2
plot f(x) w filledcurves x2 fs transparent pattern 5 lc "black" notitle, \
f(x) w filledcurves x2 fs lc "green", \
f(x) w l lc "black" dt 2 lw 1.3, \
g(x) w filledcurves x1 fs transparent pattern 4 lc "black" notitle, \
g(x) w filledcurves x1 fs lc "yellow", \
g(x) w l lc "black" dt 3 lw 1.3
### end of script
Result: