Set custom background color for key in Gnuplot

和自甴很熟 提交于 2020-06-17 01:45:31

问题


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:


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:

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


来源:https://stackoverflow.com/questions/58577151/set-custom-background-color-for-key-in-gnuplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!