1

I want to fill a number of closed curves using Gnuplot. This is the result I get so far.

enter image description here

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.

enter image description here

1 Answer 1

0

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)
2
  • Not only a very precise answer, but I could learn a couple of new things and you were even faster answering than I was writing the question. I'll give it a try before marking it as answered, but I'm pretty sure it will work. Thanks.
    – Pythonist
    Jul 2, 2015 at 8:24
  • Just for the sake of curiosity, I have edited the question to add the final output. I hope this is not against the rules of the web. Pretty neat, although the shading has ugly artefacts that I would like to remove. But I guess this is topic for another question.
    – Pythonist
    Jul 2, 2015 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.