2

Is it possible to change the opacity of the key's background in gnuplot? I can only find the option to toggle between opaque or transparent.

Here is an example using python's matplotlib - https://matplotlib.org/3.2.0/_images/dflt_style_changes-14.png

simwill87
  • 21
  • 1

2 Answers2

3

This is possible in the development version (5.5) and in the most recent release version (5.4.2) but not in earlier versions.

set key box opaque fillcolor "0x7faaaaaa"
Ethan
  • 13,715
  • 2
  • 12
  • 21
0

There is a cumbersome workaround for filling the key box with a custom color: Set custom background color for key in Gnuplot. However, it seems like semi-transparent colors are not accepted as terminal background.

Well, either you want to see the data and place the legend next to it or you cover the data with the legend, then the data is not "important". Putting a semi-transparent legend box on top of data seems to me a bit of a strange mix of both.

The only workaround I see currently is to manually place a semi-transparent box on top of the plot and behind the legend. The only way I succeeded so far to get this into the right layer stacking order is to plot a box with boxxyerror and add the legend via keyentry. You can put the coordinates and size of the box e.g. into the datablock $myBox. A pretty ugly workaround, but I'm happy to learn about better solutions.

Code:

### manual workaround for semi-transparent fill of key box
reset session

set style fill solid 1.0
set key center at 0,-0 noautotitle box

$myBox <<EOD
0  -0  1.25  1.25
EOD

plot  x w filledcurves x1 lc rgb 0xccff0000, \
     -x w filledcurves x1 lc rgb 0xcc0000ff, \
     $myBox u 1:2:3:4 w boxxy lc rgb 0x77ffffff noautoscale, \
     keyentry w filledcurves x1 lc rgb 0xccff0000 ti "x" , \
     keyentry w filledcurves x1 lc rgb 0xcc0000ff ti "-x" 
### end of code

Result: (wxt terminal)

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72
  • as Ethan mentioned, there is an easy and straightforward way for gnuplot>=5.4.2. The above workaround should work for gnuplot >=5.2.6 and <=5.4.1. keyentry was introduced in 5.2.6. So, for older versions this can probably be adapted with another workaround. But it's probably easier to update gnuplot to the latest version. – theozh Dec 01 '21 at 12:00