6

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.

5
  • 1
    set style fill transparent applies to fill areas, like the facets making up a pm3d surface or the interior of a polygon or the filledcurves plot style. It does not apply to lines and points. Your plot command appears to use points since you give a pointsize option, although the set of commands is incomplete so I am not 100% certain. Commented Feb 16, 2020 at 20:35
  • Does this answer your question? Gnuplot: How to make scatter plots with transparent points Commented Feb 17, 2020 at 9:15
  • Thanks @Friedrich. It doesn't answer the question because I cannot see an easy way to use palette at the same time. Still useful! Commented Mar 5, 2020 at 12:18
  • Ah! I also need this: a palette where all colors have some level of transparency! It's rare to hit something missing in gnuplot. Commented Dec 16, 2021 at 7:00
  • I just asked for this gnuplot feature on sourceforge, Commented Dec 16, 2021 at 7:11

2 Answers 2

7

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

Sign up to request clarification or add additional context in comments.

5 Comments

Works for me. Thanks also for the background information.
A follow-up comment: When printing myColor(x) this sometimes results in negative values. This is probably because at calculation or at printing level this results in a signed integer. Seems to work fine, but maybe @theozh could help clarify?
I don't know how exactly you are using it. In my case x in myColor(x) is only for 0<=x<=1. There should not be negative values with the formulae r(x),g(x),b(x) given above.
If I print a few sample values, e.g., repeatedly execute print(myColor(0.5)) I get negative values. Gnuplot 5.2 patchlevel 2. It seems to work and I assume it's a conversion between signed and unsigned under the hood, but I thought I'd mention.
apparently, gnuplot is interpreting it right as unsigned. Just for checking, try: do for [i=1:100] { print sprintf("%08x % 11u", myColor(0.5), myColor(0.5))}, which will print 100 random colors and if you format them as %u, they are all positive ;-). Btw, in the gnuplot documentation I can't find format specifier %u in the list.
3

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.