我用 gnuplot
在哑绘图模式下(直接在终端中绘图)在命令行中构建监控工具。我想为我的图表添加颜色。
这是一个简单的 View :
> gnuplot5 -e "set term dumb 70 20; plot 'file1' pt '@'"
100 +-+-------+---------+---------+---------+---------+-------+-@
+ + + + + + +
90 +-+ 'file1' @ +-+
80 +-+ @ +-+
| |
70 +-+ @ +-+
| |
60 +-+ @ +-+
50 +-+ @ +-+
| |
40 +-+ @ +-+
| |
30 +-+ @ +-+
20 +-+ @ +-+
+ + + + + + +
10 +-+--@----+---------+---------+---------+---------+-------+-+
0 10 20 30 40 50 60
与文件1:
5 10
10 20
15 30
20 40
25 50
30 60
35 70
40 80
50 90
60 100
我尝试添加颜色:
> gnuplot5 -e "set term dumb 70 20; plot 'file1' pt '@'" |
sed 's|@|\\\033[31m@\\\033[0m|g' | cat -v
100 +-+-------+---------+---------+---------+---------+-------+-\@33[31m@\@33[0m
+ + + + + + +
90 +-+ 'file1' \@33[31m@\@33[0m +-+
80 +-+ \@33[31m@\@33[0m +-+
| |
70 +-+ \@33[31m@\@33[0m +-+
| |
60 +-+ \@33[31m@\@33[0m +-+
50 +-+ \@33[31m@\@33[0m +-+
| |
40 +-+ \@33[31m@\@33[0m +-+
| |
30 +-+ \@33[31m@\@33[0m +-+
20 +-+ \@33[31m@\@33[0m +-+
+ + + + + + +
10 +-+--\@33[31m@\@33[0m----+---------+---------+---------+---------+-------+-+
0 10 20 30 40 50 60
最佳答案
解决方案一
使用grep --colors=always <pattern>
,它使用 grep 默认颜色突出显示。
> gnuplot5 -e "set term dumb 70 20; plot 'file1' pt '@'" |
grep --color=always '@'
解决方案二
使用
colout <pattern> <color>
.它可以选择颜色,但必须安装 python 库(pip install colout
)。> gnuplot5 -e "set term dumb 70 20; plot 'file1' pt '@'" | colout '@' green
关于shell - 在术语哑绘图模式下在 gnuplot 生成的图形中注入(inject)颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36729667/