Gnuplot filledcurves for closed lines doesn't work properly - gnuplot

I have a problem with gnuplot filled curves. I calculated some data to draw a picture using this code:
plot 'cont.dat' u 1:2 w filledcurves closed lc rgb "#ADFF2F" title "DF"
'cont2.dat' u 1:2 w filledcurve lc rgb "#CD5C5C" title "DA",\
'cont3.dat' u 1:2 w filledcurve lc rgb "#4682B4" title "(DF+DA)/2",\
'cont3.dat' u 1:2 w l lw 3 lc rgb "#4682B4" notitle ,\
'cont.dat' u 1:2 w l lw 3 lc rgb "#ADFF2F" notitle,\
'cont2.dat' u 1:2 w l lw 3 lc rgb "#CD5C5C" notitle
And everything was fine with this data:
But when I calculated another case. Trying to draw using the same code I received the following wrong result:
How could I change my code to fill the areas fully? I don't need this transparent 'holes'.
UPD:Here you can find data of green area which have been plotted wrong:
https://www.dropbox.com/s/xzheur2mx9h902f/cont.dat?dl=0
It doesn't matter either you plot three curves ore just one the result for each curve is the same.
I used GNUplot 4.6 for Windows

As mentioned in the comments, one of the problems in your data is that it is separated into blocks. But solving this issue is not enough. Let us focus in the figure below:
The figure on top corresponds to your original data. I plotted each data-block with different colors. If we remove the white spaces, the middle/blue figure is obtained, so the issue is not resolved yet.
If you look into the data, the first column of each data-block is sorted in the direction of the arrows (top figure), but the data-blocks are sorted in the opposite direction: They are disconnected!
So, the data-blocks should be sorted as 0-4-3-2-1 (or any cyclic order, such as 3-2-1-0-4). The white spaces should also be removed. Once you do this, the bottom/red figure is obtained.
This is part of the code I used to draw the picture:
plot for [i=0:4] 'cont_original.dat' u 1:2 every :::i::i w filledc t 'original block '.i,\
'cont_nospaces.dat' u 1:($2-0.2) w filledc t 'original without spaces',\
'cont_ordered.dat' u 1:($2-0.4) w filledc t 'ordered'

Related

Gnuplot point interval from point plot

I know that I can control point interval by "pointinterval" or "pi" command. However, this command only works with "linespoint" or "lp" plotting style.
Can I manage point interval with "points" or "p" plotting style?
For example:
plot data u 1:2 w p pt 7 ps 1 pi 2000 lc rgb "red" title "density"
Here, I tried "pi 2000" for point interval with points plotting style but it is not working
In the points plotting style, you can control which data points to plot in regular intervals with the 'every' keyword. It goes right after the data file name. If you really wanted to only plot every 2000 data points:
plot "dataFile" every 2000 u 1:2 w p pt 7 ps 1 lc rgb "red" title "density"
"every" is quite sophisticated. Type 'help every' at a gnuplot prompt and you can get more details.

Gnuplot: Alternating colors in fenceplots

I want to to plot a fenceplot with alternating fence colors. In this case I want black and grey. I used the following code:
splot for [i=0:300:25] "fenceplot.csv" index i u 1:2:3 w lines
The number of fences defined in my data file is dynamic and is usually between 250-350 fences.
Because the variable i changes by 25 between subsequent curves you can decide which color to use for a given line by testing whether i is even or odd:
set style line 1 linecolor "black"
set style line 2 linecolor "grey"
splot for [i=0:300:25] "fenceplot.csv" index i u 1:2:3 w lines linestyle 1+i%2
Slightly more robust would be
splot for [i=0:12] "fenceplot.csv" index i*25 u 1:2:3 w lines linestyle 1+i%2
because then you can also replace 25 by an even number.

gnuplot with lines is not working

I'm having a very difficult time getting "with lines" to work with gnuplot 4.6. I have a the following styles
set style line 2 lc 7 lt 1 pt 7 lw 1.5
set style line 3 lc 1 lt 1 lw 4.0
and I use the following plot command
plot '-' using 1:2 w lp ls 2 title 'test1','-' using 1:3 w lp ls 3 title 'test2'
NOTE lp in second plot
everything works fine, but I want to remove the data points from the second plot, so I've tried the following command
plot '-' using 1:2 w lp ls 2 title 'test1','-' using 1:3 w l ls 3 title 'test2'
NOTE l in second plot
but it fails to plot anything. The legend indicates that the style was picked up correctly, but there is no plot.
What am I doing wrong? Is there a way to use "linepoints" and shut off the points? I just want a line in the second plot.
I figured it out. I was passing one to many "\n" characters to pipe. It's interesting that it worked with both commands being "linepoints" but when one was changed to "lines" it did not work. Thanks for the input though.

Varying filling colour in Gnuplot according to certain palette

I want to fill a number of closed curves using Gnuplot. This is the result I get so far.
Not bad. I have used this code:
plot \
'fort.40' u 1:2 smooth bezier w filledcurves lt 1 lc 4 lw 3 t 't=100 s' ,\
'fort.30' u 1:2 smooth bezier w filledcurves lt 1 lc 3 lw 3 t 't=20 s' ,\
'fort.20' u 1:2 smooth bezier w filledcurves lt 1 lc 2 lw 3 t 't=1 s' ,\
'fort.10' u 1:2 smooth bezier w filledcurves lt 1 lc 1 lw 3 t 't=0'
However, what I really want is to plot like one hundred of such curves (for physicists, what I want is to illustrate the temporal evolution of a circle in the phase space of something like a double pendulum). Each closed curve is stored as two columns with the coordinates of the curve in a different ASCII file. As you see, I have achieved the figure above with four different filling colours set by hand. But now I would like to generalise it to have a smooth transition of colours, following certain palette. The idea is that the colour gives an hint about the third dimension implicit in the figure: time.
Do you know if it is possible at all to use a filling colour that follows certain palette, instead of a fixed colour? In the worst case, I could define 100 filling styles (I create the code within a shell script, so it is relatively easy to automatise the process), but still I do not know whether it is possible to assign a colour based on a palette, instead of a colour giving by hand.
EDIT: Thanks to the excellent answer by #Christoph, this is the final output. I leave it here just to illustrate how powerfull Gnuplot can be.
The filledcurves plotting style doesn't support lc palette or lc [rgb] variable, which is what one would use to color lines.
For filledcurves you can use lc palette frac <value>, where <value> is a number in the range [0:1] which specifies the fractional position in the current palette, where the color is taken from. That requires you to know the number of files you are plotting:
set style fill solid noborder
plot \
'fort.40' u 1:2 smooth bezier w filledcurves lc palette frac 1 t 't=100 s' ,\
'fort.30' u 1:2 smooth bezier w filledcurves lc palette frac 0.6667 t 't=20 s' ,\
'fort.20' u 1:2 smooth bezier w filledcurves lc palette frac 0.3333 t 't=1 s' ,\
'fort.10' u 1:2 smooth bezier w filledcurves lc palette frac 0 t 't=0'
To iterate over the files you could use
files = 'fort.40 fort.30 fort.20 fort.10'
times = '100 20 1 0'
N = words(files)
set style fill solid noborder
plot for [i=1:words(files)] word(files, i) u 1:2 smooth bezier with filledcurves lc palette frac (N-i)/(N-1.0) t sprintf('t=%s s', word(times, i)

gnuplot - removing line title

I tried searching, but I couldn't find the solution for this particular condition. In my plot , I am comparing two traces. I am using a line graph and both traces are plotted with different colors.
plot "delay_try1.dat" using 1:2 title 'With CloneScale' with lines, \
"normal_2.dat" using 1:2 title "Without CloneScale" with lines lc rgb "black", \
"normal2.dat" using 1:2 title 'Without CloneScale' with lines lc rgb "black"
Using this plot command, I get 3 titles in legends and 2 are repeating ones. I just want 2 titles to appear and remove the repeating one. Is it possible to do this?
To accomplish this you should use the notitle tag.
plot "delay_try1.dat" using 1:2 title 'With CloneScale' with lines, "normal_2.dat" using 1:2 title "Without CloneScale" with lines lc rgb "black", "normal2.dat" using 1:2 with lines lc rgb "black" notitle
or a more general example;
plot 'File.dat' using 1:2 notitle
an alternative that is equivalent to notitle is to set the title to a zero character string;
plot 'File.dat' using 1:2 title ""
If you had more untitled lines than titled lines, it's more convenient to disable titles by default using set key noautotitle:
set key noautotitle
plot "delay_try1.dat" using 1:2 title 'With CloneScale' with lines, \
"normal_2.dat" using 1:2 title "Without CloneScale" with lines lc rgb "black", \
"normal2.dat" using 1:2 with lines lc rgb "black"
If you are not above a bit of trickery:
Just omitting the last "Without CloneScale" title will remove both title and line from the legend.
Setting the last title to a space will show the line and (seemingly) nothing before it in the legend:
plot "delay_try1.dat" using 1:2 title 'With CloneScale' with lines,"normal_2.dat" using 1:2 title "Without CloneScale" with lines lc rgb "black", "normal2.dat" using 1:2 title ' ' with lines lc rgb "black"

Resources