gnuplot如何用单命令统一设置前景及文本颜色?
Gnuplot统一设置浅色前景的简化方案
gnuplot确实没有直接的set foreground或全局字体颜色命令,但可以通过定义变量+批量引用的方式,避免重复设置十几个参数,达到类似全局修改的效果。
优化后的代码示例
#!/usr/bin/env gnuplot # 定义全局前景色和背景色变量 fg_color = "#ffffff" bg_color = "#000000" set terminal svg size 1024,640 background rgb bg_color set output 'output.svg' # 所有需要浅色的地方直接引用变量 set key textcolor rgb fg_color set title "some title" textcolor rgb fg_color set xlabel "domain" textcolor rgb fg_color set ylabel "range" textcolor rgb fg_color set border linecolor rgb fg_color set style data lines # 预设线条样式,后续plot命令可直接调用 set style line 1 lc rgb fg_color plot x**2 title "some function" with lines ls 1
说明
- 只需要修改
fg_color变量的值,就能一次性同步所有文本、边框、线条的颜色,不用逐个修改参数 - 用
set style line预设样式后,后续的plot命令可以直接用ls 1调用,进一步简化代码 - 部分终端(如qt)支持
set terminal qt foreground rgb ...的全局设置,但svg终端不支持该参数,因此变量法是最通用的跨终端解决方案
内容的提问来源于stack exchange,提问作者thenumbernine
相关产品推荐
相关产品推荐

