gnuplot - filled curve with palette color - gnuplot

I'm trying to plot a histogram in gnuplot, where the bars are characterized by their color (intensity) instead of their height (frequency). To do so, I want to fill each bar with a color corresponding to the third column (which stands for this intensity) of a data file, defined in a palette. All the bars have the same height y=1 and the same width dx=1. The important part of the script looks like
plot for [ii=0:N] 'data.dat' index ii u 1:2:3 w filledcu y1=0 lc palette
My problem is that the ii=0 takes the right color of the palette and fills the first bar, but from there on all the others are the same color ( same intensity ) than ii=0.
My data file looks like:
X Y Intensity
1 1 0.6
2 1 0.6
...
Any idea to fill with the right color ?

The filledcurves plotting style doesn't support color gradients, see Gnuplot filledcurves with palette.
Since you have the same height for every bar, you can use the boxes plotting style:
set style fill solid noborder
plot 'data.dat' using 1:2:3 with boxes lc palette

Related

Can't use palette to fill object with colour

I was trying to plot number of particles in a square lattice. and I need each one to be coloured different. So I tried using palette.. by picking some random numbers but it always gives me black rectangles.. what should I do?
set obj rect from 1,5 to 2,6 fc palette 0.454545 → this is what is not working for me.
This is the image with all same color. I need different colour for each particle:
Plot using the boxxyerror style, and fill the boxes:
set size ratio -1
set style fill solid
plot 'file.dat' using 1:2:(0.1):(0.1):3 linecolor palette with boxxyerror
This would plot a square of size 0.2 at each position given by the first and second columns. The color is taken from the third column and mapped to the current palette. You must adapt that to your actual data format.
Working example using random pseudo-data ('+'):
set xrange [-0.05:1.05]
f = "int(rand(0) * 20)/20.0"
set style fill solid
set size ratio -1
plot '+' using (#f):(#f):(0.025):(0.025):(#f) linecolor palette notitle with boxxyerror
see What I gotI could get this working,what I did is initially set the pallette by the commands like "set palette model RGB defined ( 0 'green', 1 'blue', 2 'red', 3 'orange' )" ,"set palette model HSV defined ( 0 0 1 1, 1 1 1 1 )"(I got these from here-http://gnuplot.sourceforge.net/demo/pm3dcolors.html). Then I set rectangles as "set obj rect from x1,y1 to x2,y2 fc palette frac 0.57" . But I could see that there were some gaps between the squares and I could understand that it was because of problem with border so I added this "fs border palette frac 0.57",same colour. Even after doing these It wouldn't come out by the simple command "plot 0". So I had to modify it as "plot 0 lc palette frac 0.24 " (0.57 / 0.24 I just meant as example.. as you know it would be anything between 0 and 1). Now to remove the colorbox I used "unset colorbox". But why I had to write "plot 0 lc palette frac 0.24 " ?, to wakeup the palette? ,Is there any other way to show out the rectangles that we have already set without using a plot command ?

Gnuplot: fill area bounded by curves left/right?

I have a dataset that defines two curves, and I want to fill the area between them. However, contrary to the standard situation, the abscissa is to be plotted on the vertical axis and the ordinates on the horizontal one; the abscissa indicates depth, this is a common plotting format in geophysics. In other words, I want something like
plot 's.dat' u 1:2:3 w filledcurves
but with swapped axes so that the filled area is bounded not at the top and bottom but to the left and right by the curves as seen in
plot 's.dat' u 2:1,'s.dat' u 3:1
My dataset is like this:
0. -1.776 -0.880
160. -1.775 -0.882
160. -1.692 -0.799
320. -1.692 -0.800
320. -1.531 -0.634
480. -1.534 -0.637
480. -1.286 -0.394
Is this possible in Gnuplot?
Thomas
This is a totally different solution using 3D plot style "with zerror".
You will need current gnuplot (version 5.2) for this. The plot style was really not designed for this so there are some difficulties (e.g. x tic marks invisible because drawn perpendicular to the plane of the plot, all tic labels requiring an offset for readability).
#
# [mis]use 3D plot style "with zerror" to create a plot of the xz
# plane with area fill between two sets of data points with
# equal coordinates on the vertical axis (x) but contrasting
# values on the horizontal axis (z).
#
set view 270, 0
set view azimuth -90
set xyplane at 0
unset ytics
set ztics offset 4, -2 out
set xtics offset 4
splot 's.dat' using 1:(0):(0.5*($2+$3)):2:3 with zerror notitle
If there is some value of x which is guaranteed to lie between the two curves then you can plot in two halves. For the data you show, x=-1 would be a suitable value and the plot command would be:
plot 's.dat' u 2:1 with filledcurve x=-1 lt 3, \
's.dat' u 3:1 with filledcurve x=-1 lt 3
If the requirement for a constant intermediate x value can only be
satisfied piece-wise, e.g.
x=-1 for (0<y<500), x=0 for (500<y<1000)
then it may nevertheless be possible to construct a graph by stacking
the piecewise sections.
A simple way would be to define a closed line and fill it. For this, you take column 2 and add the reversed column 3. You probably need gnuplot >=5.2 for this.
Code:
### fill between vertical curves
reset session
$Data <<EOD
0. -1.776 -0.880
160. -1.775 -0.882
160. -1.692 -0.799
320. -1.692 -0.800
320. -1.531 -0.634
480. -1.534 -0.637
480. -1.286 -0.394
EOD
set print $Outline
do for [i=1:|$Data|] {
print sprintf("%s %s", word($Data[i],2), word($Data[i],1))
}
do for [i=|$Data|:1:-1] {
print sprintf("%s %s", word($Data[i],3), word($Data[i],1))
}
set print
plot $Outline w filledcurve lc rgb "green"
### end of code
Result:

transparent point plot does not work [duplicate]

How can I plot an image with partially transparent scatter points, just like in the picture below, with Gnuplot? The problem is that I don’t know how to set the points to be transparent.
Try this:
set style fill transparent solid 0.35 noborder
set style circle radius 0.02
plot 'test' u 1:2 with circles lc rgb "blue", \
'' u 1:2 every 100 w circles lc rgb "red" fs solid 1.0 border lt -1
which outputs
As you can see, you can specify for each data set whether to use transparency and which color to use.
If your data consist of two values (x and y position of the circle) you have to specify the circle's radius via set style circle .... If your data has three rows, you can use the third value to specify the circle's radius for each data point.
You can play with the transparency level, which ranges from 0 (full transparency) to 1 (no transparency).
You can use the alpha channel of argb along with lc rgb variable:
set samp 2000
randn(x) = invnorm(rand(x))
pl [-3:3][-3:3] '+' us (randn(0)):(randn(0)):(0xBB00AAFF) lc rgb variable pt 7 ps 2
.
This leaves some egde around each circle, probably an opacity effect from a circle plus a filled circle on top of it. Unfortunately, there is no edgecolor option as in matplotlib to control this. Replacing filled circles pt 7 with open circles but thick linewidth pt 6 lw 6 can mitigate this a bit
pl [-3:3][-3:3] '+' us (randn(0)):(randn(0)):(0xBB00AAFF) lc rgb variable pt 6 lw 6
.
One can also emulate a variable transparency with lc rgb variable
set samp 50
pl '+' us 1:1:(0x00AAFF+(int(0xFF*$1/10.)<<24)) pt 7 lc rgb variable ps 3
where int(0xFF*$1/10.) maps the input from 0..10 into 0..255 and <<24 shifts it into the alpha channel.
Note that in your plot only the dense regions seem to have a transparency effect, but not the scatter points in the background.

How to make scatter plots with semitransparent points in Gnuplot?

How can I plot an image with partially transparent scatter points, just like in the picture below, with Gnuplot? The problem is that I don’t know how to set the points to be transparent.
Try this:
set style fill transparent solid 0.35 noborder
set style circle radius 0.02
plot 'test' u 1:2 with circles lc rgb "blue", \
'' u 1:2 every 100 w circles lc rgb "red" fs solid 1.0 border lt -1
which outputs
As you can see, you can specify for each data set whether to use transparency and which color to use.
If your data consist of two values (x and y position of the circle) you have to specify the circle's radius via set style circle .... If your data has three rows, you can use the third value to specify the circle's radius for each data point.
You can play with the transparency level, which ranges from 0 (full transparency) to 1 (no transparency).
You can use the alpha channel of argb along with lc rgb variable:
set samp 2000
randn(x) = invnorm(rand(x))
pl [-3:3][-3:3] '+' us (randn(0)):(randn(0)):(0xBB00AAFF) lc rgb variable pt 7 ps 2
.
This leaves some egde around each circle, probably an opacity effect from a circle plus a filled circle on top of it. Unfortunately, there is no edgecolor option as in matplotlib to control this. Replacing filled circles pt 7 with open circles but thick linewidth pt 6 lw 6 can mitigate this a bit
pl [-3:3][-3:3] '+' us (randn(0)):(randn(0)):(0xBB00AAFF) lc rgb variable pt 6 lw 6
.
One can also emulate a variable transparency with lc rgb variable
set samp 50
pl '+' us 1:1:(0x00AAFF+(int(0xFF*$1/10.)<<24)) pt 7 lc rgb variable ps 3
where int(0xFF*$1/10.) maps the input from 0..10 into 0..255 and <<24 shifts it into the alpha channel.
Note that in your plot only the dense regions seem to have a transparency effect, but not the scatter points in the background.

Gnuplot histogram gap does nothing

I have a gnuplot script which plots a histogram. I used the following syntax:
set style data histogram
set style histogram cluster gap 2
set style fill solid
set logscale y
rgb(r,g,b) = int(r)*65536 + int(g)*256 + int(b)
plot 'histogram_data' using (column(0)):2:(0.5):(rgb($3,$4,$5)):xticlabels(1) w boxes notitle lc rgb variable
What the last line does is: using column 1 as x labels, column 2 as the height of the histogram bars, 0.5 as box width, and columns 3, 4 and 5 as the rgb values to colour the bars.
Now, the problem is that modifying the gap parameter in line 2 does not change in any way the spacing between bars, even though as far as I understand that is the correct way to adjust such spacing. I am using gnuplot 4.6 patchlevel 4.
I found a way to do this with boxes, though I do not consider it very clean:
plot 'histogram_data' u (column(0)*2+1):2 w boxes notitle lc rgb 'white',\
'histogram_data' u (column(0)*2):2:(rgb($3,$4,$5)):xticlabels(1) w boxes notitle lc rgb variable;
This command is plotting all the data of the main plot on even slots and a white box on odd slots. So the first line in the plot command is plotting the gaps between every box of the plot (the width of these gaps can be specified using the boxwidth property I think but I haven't tested this), while the second line is drawing the actual plot.
I could not find a way to do this with the histogram plotting style, keeping the variable colours specified in the data file.

Resources