Varying filling colour in Gnuplot according to certain palette - gnuplot

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)

Related

Gnuplot: "Complementary" dashed lines

I would like to plot "complementary" dashed lines. What I mean is the following: I have three curves that are identical in a certain range of x values but different outside this range. Of course, if I simply plot solid lines on top of each other, I will only see the topmost one (in the range where they are identical). So, I would like to plot them as dashed lines:
1st line: dash-space-space-dash-space-space...
2nd line: space-dash-space-space-dash-space...
3rd line: space-space-dash-space-space-dash...
Plotting them on top of each other should produce a solid lines with alternating colors (of the three line types).
The most obvious way to achieve this is with the new dashtypes, for example:
plot x dt "- ",x dt " - ",x dt " -"
However, the leading blank is ignored. Also, a definition such as (20,20) does not work because the order of values is always "solid length,emptyspace length". If there were a way to invert this order, the problem could be solved easily.
(By the way, in the case of only two curves, the solution is simple: plot the first as solid and the second as dashed.)
Any ideas?
You are probably looking for something like this:
### different shifted dashed lines
reset session
plot x, \
0 w l lw 3 lc rgb "red" dt (20,40) notitle, \
0 w l lw 3 lc rgb "web-green" dt (0,20,20,20) notitle, \
0 w l lw 3 lc rgb "blue" dt (0,40,20,0) notitle
### end of code
Addition:
with the following code the result should be the same (or let's say similar) in wxt, qt, postscript, pngcairo (cannot test x11). Well, the dash length is different depending on the terminal (see https://stackoverflow.com/a/55628295/7295599)
### different shifted dashed lines
reset session
# set term wxt
# set term qt
set term pngcairo
set output "DashedLines.png"
# set term postscript color
# set output "DashedLines.eps"
plot x, \
0 w l lw 3 lc rgb "blue" dt 1 notitle, \
0 w l lw 3 lc rgb "web-green" dt (40,20) notitle, \
0 w l lw 3 lc rgb "red" dt (20,40) notitle
set output
### end of code

Gnuplot filledcurves for closed lines doesn't work properly

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'

Change the color of the points in labelled plot

The script works, without any change in color, however:
plot '_numXY' using 2:3:(sprintf('%d', $1)) \
with labels offset 0,1 point pointtype 6 ps 2 notitle lc rgb "blue"
The points are black. I want to see the points in blue color.
Why does lc rgb "blue" not work?
The lc settings are ignored for the labels plotting style if they don't follow immediately the point option. In your case you must only place the notitle at the end.
plot '_numXY' using 2:3:(sprintf('%d', $1)) \
with labels offset 0,1 point pointtype 6 ps 2 lc rgb "blue" notitle
As a demonstration example:
set samples 11
set xrange [0:10]
plot '+' using 1:1:(sprintf('%d', $1)) \
with labels offset 0,1 point pointtype 6 ps 2 lc rgb "blue" notitle
The result with 4.6.5 is:

Fill several sections below a curve of data in Gnuplot

I have a set of points "data" defining a curve that I want to plot with bezier smooth.
So I want to fill the area below that curve between some pairs of x values.
If I only had one pair of x values it's not that difficult because I define a new set of data and plot it with filledcu. Example:
The problem is that I want to do that several times in the same plot.
Edit: Minimal working example:
#!/usr/bin/gnuplot
set terminal wxt enhanced font 'Verdana,12'
set style fill transparent solid 0.35 noborder
plot 'data' using 1:2 smooth sbezier with lines ls 1
pause -1
Where the structure of 'data' is:
x_point y_point
And I realized that my problem is that in fact I can't fill not even one curve, it seems to be filled because the slope is almost constant there.
To fill parts below a curve, you must use the filledcurves style. With the option x1 you fill the part between the curve and the x-axis.
In order to fill only parts of the curve, you must filter your data, i.e. give the x-values a value of 1/0 (invalid data point) if they are outside of the desired range, and the correct value from the data file otherwise. At the end you plot the curve itself:
set style fill transparent solid 0.35 noborder
filter(x,min,max) = (x > min && x < max) ? x : 1/0
plot 'data' using (filter($1, -1, -0.5)):2 with filledcurves x1 lt 1 notitle,\
'' using (filter($1, 0.2, 0.8)):2 with filledcurves x1 lt 1 notitle,\
'' using 1:2 with lines lw 3 lt 1 title 'curve'
This fills the range [-1:0.5] and [0.2:0.8].
To give a working example, I use the special filename +:
set samples 100
set xrange [-2:2]
f(x) = -x**2 + 4
set linetype 1 lc rgb '#A3001E'
set style fill transparent solid 0.35 noborder
filter(x,min,max) = (x > min && x < max) ? x : 1/0
plot '+' using (filter($1, -1, -0.5)):(f($1)) with filledcurves x1 lt 1 notitle,\
'' using (filter($1, 0.2, 0.8)):(f($1)) with filledcurves x1 lt 1 notitle,\
'' using 1:(f($1)) with lines lw 3 lt 1 title 'curve'
With the result (with 4.6.4):
If you must use some kind of smoothing, the filter may affect the data curve differently, depending on the filtered part. You can first write the smoothed data to a temporary file and then use this for 'normal' plotting:
set table 'data-smoothed'
plot 'data' using 1:2 smooth bezier
unset table
set style fill transparent solid 0.35 noborder
filter(x,min,max) = (x > min && x < max) ? x : 1/0
plot 'data-smoothed' using (filter($1, -1, -0.5)):2 with filledcurves x1 lt 1 notitle,\
'' using (filter($1, 0.2, 0.8)):2 with filledcurves x1 lt 1 notitle,\
'' using 1:2 with lines lw 3 lt 1 title 'curve'

How do I plot 2-dimensional data in circles where radius representing the 3rd column and the color representing the 4th column?

Here is an example data set.
#x y r c
1 2 10 2
3 1 2 4
3 2 1 5
I can plot with circle's radius representing the 3rd column OR with color representing the 3rd column. However, I don't know how to keep them both in the plot.
Here is my code to plot with radius representing the 3rd column.
plot 'rslt.log' u 1:2:3 w points pt 7 ps variable
Try:
plot 'rslt.log' u 1:2:3:4 w points pt 7 ps variable lc palette
An alternative is:
plot 'test.dat' u 1:2:3:4 w p pt 7 ps variable lc variable
or using the circles linestyle:
plot 'test.dat' u 1:2:3:4 w circles linecolor variable
If you want solid filled circles:
plot 'test.dat' u 1:2:3:4 w circles linecolor variable fillstyle solid
For any of the above, you can substitute linecolor variable with linecolor palette as suggested by #andyras. The difference is that palette maps a floating point number onto the palette whereas variable maps the integer to a linestyle which has a color associated with it.
With ps variable the number in the associated column becomes a multiplicative factor which increases the default size of the point. With circles you have the freedom to specify the exact size of the circle (as the radius) -- Although I'm not 100% sure which axis is used in the common case where the aspect ratio of your plot isn't 1.

Resources