除了@user8153 的解决方案,我想提出一个更通用的解决方案。
如果你有彩色背景怎么办?例如:set term wxt background rgb "grey90" 或者如果
你有一个彩色键(或图例)框......嗯,嗯,gnuplot 不提供选项
钥匙盒的彩色背景。那么,如果你在钥匙后面放一个彩色矩形。
当然,您可以随时根据背景调整颜色,但我想用lt -2 或lt nodraw 绘制一条不可见的线会更简单。
关于lt -2或lt nodraw,前几天刚在这里了解到:gnuplot: why is linewidth 0 not zero in width?。虽然它似乎从 gnuplot 5.0 版开始就已经存在,但它(还没有)在手册中。
代码:
### invisible keyentry for column/row arrangement
reset session
set key top left maxrows 3
set obj 1 rect from graph 0.02,0.82 to graph 0.52,0.98 fs solid 1.0 fc rgb "grey90"
set xrange[-2:2]
set yrange[-2:2]
plot sin(x), sin(2*x), sin(3*x), exp(x), NaN lt -2 ti " "
### end of code
结果:
加法:
实际上,我忘记了按键箱的彩色背景有一种解决方法。无需手动调整和摆弄盒子:
Set custom background color for key in Gnuplot
如果您想要透明背景,例如用于网页上的图像,例如pngcairo、pdfcairo 等,除了lt -2 或lt nodraw,另一种解决方案是绘制一条透明线,例如透明的“黑色”lc rgb 0xff000000:
plot sin(x), sin(2*x), sin(3*x), exp(x), NaN lc rgb 0xff000000 ti " "
代码:
### invisible keyentry for column/row arrangement with transparent background
reset session
set term pngcairo transparent
set output "tbKeyRows.png"
set key top left maxrows 3
set xrange[-2:2]
set yrange[-2:2]
plot sin(x), sin(2*x), sin(3*x), exp(x), NaN lt -2 ti " "
set output
### end of code
结果:(显示在棋盘图案前面)