Search code examples
gnuplot

How can I make the key for a plot in Gnuplot not have transparency when the plot itself has transparency?


I'm trying to make a "density" type scatter plot, where each point is a transparent circle, so when they overlap it makes a density map. I'm doing this with a huge number of samples, so the transparency is very low, but this means it's impossible to see the key. Can I make the key's transparency different than the actual plots?

This is what I have:

if (!exists("outfile")) outfile='plot.pdf'

set terminal pdf enhanced size 8in, 4.8in
set output outfile

set style fill transparent solid 0.1 noborder
set style circle radius 0.03

plot sample1 u 1:2 w circles, sample2 u 1:2 w circles

example plot


Solution

  • Simply use keyentry and with points pt 7. Check help keyentry.

    Code:

    ### keyentry
    reset session
    
    # create some random test data
    set samples 10000
    set table $Data1
        plot '+' u (invnorm(rand(0))+1):(invnorm(rand(0))+1) w table
    set table $Data2
        plot '+' u (invnorm(rand(0))+4):(invnorm(rand(0))+4) w table
    unset table
    
    set style fill transparent solid 0.1 noborder
    set style circle radius 0.03
    
    plot $Data1 u 1:2 w circles notitle,\
         $Data2 u 1:2 w circles notitle, \
         keyentry w p pt 7 lc 1 title "Data1", \
         keyentry w p pt 7 lc 2 title "Data2"
    ### end of code
    

    For older "pre-keyentry" gnuplot versions you could exchange the keyentry lines by:

     NaN w p pt 7 lc 1 title "Data1", \
     NaN w p pt 7 lc 2 title "Data2"
    

    Result:

    enter image description here