问题
Is there a way to plot transparent data points when using palette?
I currently have the following code:
set style fill transparent solid 0.2 noborder
set palette rgb 22,13,-22
plot 'mydata.dat' u 1:2:3 ps 0.3 palette
My feeling is that transparency is overwritten by the arguments of the plot command.
回答1:
Is there a way to plot transparent data points when using palette?
If you check help palette
you will not find (or I overlooked) a statement about transparency in the palette. It looks like you can set the palette in different ways for RGB
, but not for ARGB
(A=alpha channel for transparency). So, I assume it is not possible with palette to have transparency (please correct me if I am wrong).
As workaround you have to set your transparency "manually" by setting the color with some transparency.
You can find the formulae behind the palettes by typing show palette rgbformulae
.
The following examples creates a plot with random point positions in xrange[0:1]
and yrange[0:1]
and random points size (from 2 to 6) and random transparency (from 0x00
to 0xff
). The color is determined by x
according to your "manual palette". I hope you can adapt this example to your needs.
Code:
### "manual" palette with transparency
reset session
# These are the rgb formulae behind palette 22,13,-22
set angle degrees
r(x) = 3*x-1 < 0 ? 0: (3*x-1 > 1) ? 1 : 3*x-1
g(x) = sin(180*x)
b(x) = 1-(3*x-1) < 0 ? 0: (1-(3*x-1) > 1) ? 1 : 1-(3*x-1)
set xrange [0:1]
set yrange[-0.1:1.1]
RandomSize(n) = rand(0)*4+2 # random size from 2 to 6
RandomTransp(n) = int(rand(0)*0xff)<<24 # random transparency from 0x00 to 0xff
myColor(x) = (int(r(x)*0xff)<<16) + (int(g(x)*0xff)<<8) + int(b(x)*0xff) + RandomTransp(0)
set samples 200
plot '+' u (x=rand(0)):(rand(0)):(RandomSize(0)):(myColor(x)) w p pt 7 ps var lc rgb var not
### end of code
Result:
来源:https://stackoverflow.com/questions/60250928/gnuplot-transparency-of-data-points-when-using-palette