Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnuplot: transparency of data points when using palette

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.

like image 297
wpm Avatar asked Feb 16 '20 17:02

wpm


2 Answers

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:

enter image description here

like image 102
theozh Avatar answered Nov 19 '22 13:11

theozh


New answer for Dev version 5.5

The new function set colormap allows to define a transparent palette. First, one defines the fully opaque palette in the usual way, then creates a copy of it and adds transparency to all points:

set palette rgb 22,13,-22
set colormap new MYPALETTE
transparency = 0.5
do for [i=1:|MYPALETTE|] {MYPALETTE[i] = MYPALETTE[i] + (int(transparency*0xff)<<24)}
func(x,y) = x*y
splot func(x,y) w pm3d fillcolor palette MYPALETTE

enter image description here

Of course, this will also work for points, the command in your case will be plot 'mydata.dat' u 1:2:3 ps 0.3 lc palette MYPALETTE

like image 21
Eldrad Avatar answered Nov 19 '22 13:11

Eldrad