Variable transparency is possible in Gnuplot?

2019-08-05 19:59发布

问题:

I want to plot a filled circle in Gnuplot, but with transparency changing with the distance to the center of the circle, i.e. a transparency gradient (solid near to the center, and transparent near to the radius of circle).

Is there any way of doing this in Gnuplot?

Thank you in advance!

回答1:

One option would be to define a custom function describing the gradient (e.g., a Gaussian) and then use pm3d map to visualize it:

set terminal pngcairo size 400,400
set output 'fig.png'

unset border
unset colorbox
unset xtics
unset ytics

set pm3d map

#force the plot to occupy the entire canvas
set lmargin at screen 0
set rmargin at screen 1
set tmargin at screen 1
set bmargin at screen 0

set isosamples 100,100

#specify custom palette
set palette model RGB
set palette defined ( 0 "white", 1 "royalblue" )

set xr [-10:10]
set yr [-10:10]

#a Gaussian might be a reasonable choice
splot exp(-0.2*(x*x+y*y))

This then produces:

Another choice of the defining function might be:

set xr [-pi:pi]
set yr [-pi:pi]
fn(r) = (r>(pi/2))?0:(cos(r))
splot fn(sqrt(x*x+y*y))

This yields:



回答2:

Try this:

set xrange [0:10]
set yrange [0:10]
do for [i=1:100] {
set style fill transparent solid i/100. noborder
set object circle at 5,5 radius 1.-i/100. fc rgb 'blue'
}
plot -1

Not all terminals support transparency; see help transparent. I made this with the terminal x11.