How to show a grid with two filled plots - gnuplot

I am plotting to datasets with 'fillsteps' one below another and I want the plot two show only the area that is a difference between the two
plot [0:1][0:1] x with fillsteps above fill solid not,x**2 with fillsteps above fill solid lc rgb 'black' not
But the grid obviously gets blocked in this case:
Is there any way to create something like a cross-section between the two areas, show the grid and get rid of those nasty artifacts that are seen below?

Ok, basically you want to fill the area between two curves (either lines or steps) and have a grid on top. The set grid front you found yourself, but let me make another suggestion.
For the first case (lines), i.e. a fill between lines, you can simply use 3 columns (check help filledcurves) and then the area will be filled between the curves:
plot '+' u 1:(f1(x)):(f2(x)) w filledcurves
For the second case (steps), I don't see (yet) such an option with filledsteps. Actually, from your option above I assume you are using gnuplot5.5.
In general, I wouldn't call it a "clean" solution if you plot something and partly have to cover it with something else with background color. What if you want a transparent background? A transparent color which covers something colored has not yet been invented ;-), there is no such "invisible" color. For another example check this.
Furthermore, with fillsteps I can also observe the artifacts of vertical gap lines which you see in your graph, but I don't have a good solution to avoid them.
Hence, my suggestion is to plot only there where you need something to plot. Actually, you can mimic the fillsteps behaviour. It's not obvious how to do it, but not too difficult. While you plot line by line, you remember the previous x-value and function values of f1(x0) and f2(x0) in x0, y0 and y2, respectively. You plot with the plotting style boxxyerror (check help boxxyerror) using x:y:xlow:xhigh:ylow:yhigh.
Script: (works with at least gnuplot>=5.0.0)
### plotting style filledcurves and mimic fillsteps "between"
reset session
f1(x) = x
f2(x) = x**2
set xrange[0:1]
set yrange[0:1]
set key noautotitle
set grid x,y front lw 1.3
set style fill solid 1.0 border
set samples 50
set multiplot layout 2,1
plot '+' u 1:(f1(x)):(f2(x)) w filledcurves
plot x1=y1=y3=NaN '+' u (x0=x1,x1=$1):(y0=y1,y1=f1($1),y2=y3,y3=f2($1)):(x0):(x1):\
(y0):(y2) w boxxy
unset multiplot
### end of script
Result: (download the PNG image and check that the background is transparent).

set grid front
works in this case

Related

Gnuplot - Multiplot autoscale displays x-axis and y-axis units twice on each other

In Gnuplot I want to display 2 plots on the same graph with the help of multiplot. The display works fine, but the scaling redisplays and the same units are put on each other, because i use autoscale.
My question is, how do i display the scaling only once?
Here is my code:
set border 1023-128
set autoscale
set multiplot
plot strDsDir.strInputFile using 1:($6/1000000) skip 1 w filledcurves x lc rgb "#00aa22"
replot strDsDir.strInputFile using 1:($7/1000000) skip 1 w filledcurves x lc rgb "#80e45f"
unset multiplot
I tried unsetting autoscale, between the "plot" and "replot", but then I lose autoscaling, and graphs slip.
I also tried unsetting xtics and ytics, but then i lose the set border 1023-128 above.
Here is the picture, where my units lapse on eachother :
And here is the picture, where units dont lapse on each other, but my "set border option" disappears :
The dataset what im trying to display doesnt matter.
Thank you.
The purpose of multiplot usually is to plot several plots beside each other. If you want to plot several curves in a single plot, use a single plot command like plot x, x**2:
plot strDsDir.strInputFile using 1:($6/1e6) skip 1 w filledcurves x lc rgb "#00aa22", \
"" using 1:($7/1e6) skip 1 w filledcurves x lc rgb "#80e45f"

Thickness of pattern fill in Gnuplot

I am using Gnuplot and I wish to fill the area between two curves with transparent hatched pattern.
I define fill style with:
set style fill transparent pattern 1
and I plot it as:
plot "Data..." using 4:1:2 with filledcurves lc rgb 'black'
However, the resulting hatched pattern has extremely thick lines. I want to adjust thickness of pattern lines, density of lines etc.
I cannot believe I could not find anyone asking the same thing?

Change color of dgrid3d surface in Gnuplot

Is there a way to change the color of the lines of the surface when using dgrid3d? It seem simple enough but everything I've looked at only speaks of coloring the whole surface using pm3d. I have multiple surfaces on one plot and would like to be able to specify the color of each. For example, one would be red, another would be blue, another would be black, another would be green.
If you have your data available in a file Data.dat then give this a try:
set dgrid3d 10,10
set style data lines
set pm3d
splot "Data.dat" pal
The dgrid3d tells gnuplot how many entries there are in the x- and
y-direction (those are the two comma separated parameters)
The style data lines lets gnuplot plot the result with lines
instead of points
The pm3d fills the surface with a color (if you leave this away you
will just see the lines)
pal makes the lines appear in the color of the specified value
There are much more options you can set, but i find those the most relevant.
Seems like.
set dgrid3d
splot "file.dat" with lines linecolor 4
Where 4 is color you need.
For multiple surfaces you can try
set dgrid3d splines
set table "surface1.dat"
splot "file1.dat"
unset table
unset dgrid3d
for every surface you need.
And after all surface description
splot "surface1.dat" with lines linecolor 4, splot "surface2.dat" with lines linecolor 7 ...

How to add custom label to Gnuplot graph legend?

In a graph I'm making with gnuplot I draw some grey lines (set arrow command), which represent the physical boundaries of my experiment (i.e., walls)
I would like to know how I can add this information on the legend of the graph, so it says "Walls" and have a grey line next to it.
I thought about creating a new series that contained this information, but I was wondering if it's possible to explicitly add it.
You can't add information directly to the legend. You can, however, either draw the legend explicitly, or plot a line which will not appear within the range of the plot, e.g.
plot [][0:1] 2 lc rgb 'gray' t 'Walls'
Or, if your x and y limits are already set:
...
[set x and y limits here]
...
plot 1e20 lc rgb 'gray' t 'Walls'
Just wanted to note: since plotting a single line tended to mess up a graph of mine, a better solution for me was to plot a single point; but as found in Plotting single points « Gnuplotting, that is kinda difficult (especially if insertion at arbitrary plot legend/key position is needed) - unless redirection is used... This is what worked for me:
plot "filename" using 1:8 \
,\
... # more plot lines here
,\
"<echo '-1 -1'" lc rgb 'white' with points title '---' \
,\
... # more plot lines here
One simple way is to make the name of the data file the legend which you want and then plot that data file.

Hide the boxes in a histogram with errorbars in gnuplot?

I have a gnuplot histogram with errorbars. How can I hide the boxes so just the errorbars remain?
I can achieve this effect for a single data set using the plain errorbars style and hiding the marker at the center, but I would like to use the histogram style to show multiple series on the same plot.
My code currently looks like this:
set style data histograms
set style histogram errorbars lw 2
plot "mydata.dat" using $2:$3:xtic(1) title "Series1", \
"" using $4:$5 title "Series2"
The following lines make the boxes too small to appear at typical zoom levels, but I'd prefer to explicitly disable them.
set boxwidth 0.00001
set style fill solid noborder
Don't do:
set style data histograms
Instead just do:
plot "mydata.dat" with errorbars
If this does not solve your question, can you point me to an image of a plot similar to what you are trying to achieve?

Resources