Question

I am running a simple sin(x) function [-10:10], and would like to have the output as transparent fill, not as just line.

The example is not really clear about what to do; since when I type this at the gnu plot prompt, I get the standard plot with the line:

set style fill transparent solid 0.5 noborder; plot [-10:10] sin(x)

IF I add anything after the sin(x), I get an error saying that the ; is expected. If I add the ; like

set style fill transparent solid 0.5 noborder; plot [-10:10] sin(x); fs solid 0.5

I get an error, saying invalid command.

I know that is not rocket science, but I don't really see what kind of syntax Gnuplot uses, to change the style. I can set lines without problems, but can't set the fill.

Was it helpful?

Solution

Give the following commands a try:

set xrange [-10:10]
set style function filledcurves above y1=0.0
set style fill transparent solid 0.5 noborder
plot sin(x) w filledcurves above y1=0.0, sin(x) w filledcurves below y1=0.0 ls 1

Or (the above, but change the plot line to):

plot sin(x) w filledcurves below y1=1.0

You also don't need to include the set style function filledcurves above y1=0.0 if you are using the w filledcurves ... in your plot line, but you can (and you can also remove the w filledcurves ... part of your plot line if you use the pre-mentioned line.

Typically in gnuplot, you can put commands on multiple lines and omit the semicolons. If you are on a nice linux system, it should be possible to create a script file, say graph.gnu, add the lines of your script and the additional line #!/usr/bin/gnuplot -p to the very top of the file, and then use chmod +x graph.gnu. The script can now be executed and should display your graph.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top