1
votes

I'm trying to plot something like this:

set key top left box opaque
set border back
plot sin(x)

but I want the key to have a different background color than the rest of the graph. For example, if the graph is white, I want to the key to have a grey background. Or something like that.

I'm relatively new to Gnuplot, but I have looked in the manual and there doesn't seem to be a direct way to do this.

Can someone suggest a solution?

Thanks.

1

1 Answers

0
votes

Yes, if you check help key, there seems to be no option to set the background color of the key box.

A workaround might be the following: With opaque, the key box will be filled with the background color. So, the "trick" is to the change the background color of the terminal to the desired key box color, but then add, e.g. a white rectangle spanning the whole screen. Do not forget to use the option behind. Additionally, to avoid a residual line at the border of the screen, set the coordinates of the rectangle from -0.1,-0.1 to 1.1,1.1. It works with wxt terminal. You need to test whether this works also with other terminals.

Code:

### key background
reset session

set term wxt background rgb "grey"

set object 1 rectangle from screen -0.1,-0.1 to screen 1.1,1.1 fc rgb "white" behind
set key opaque font ",12"

plot sin(x), cos(x)
### end of code

Result:

enter image description here

Addition:

@johnymm, for me it also works fine with pdfcairo terminal.

### key background
reset session

set term pdfcairo background rgb "grey"
set output "KeyBackground.pdf"

set style rect fc rgb "white" fs noborder
set object 1 rectangle from screen 0,0 to screen 1,1 behind

set key opaque font ",12"

plot sin(x), cos(x)
set output
### end of code