我在哑图模式中使用gnuplot
(直接在终端中绘图)在命令行中构建监控工具。我想在我的图表中添加颜色。
这是一个简单的观点:
> 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
with file1:
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
答案 0 :(得分:4)
解决方案1
使用grep --colors=always <pattern>
,它使用grep默认颜色突出显示。
> gnuplot5 -e "set term dumb 70 20; plot 'file1' pt '@'" |
grep --color=always '@'
解决方案2
使用colout <pattern> <color>
。它能够选择颜色,但必须安装python库(pip install colout
)。
> gnuplot5 -e "set term dumb 70 20; plot 'file1' pt '@'" | colout '@' green