shell - 在术语哑绘图模式下在 gnuplot 生成的图形中注入(inject)颜色

标签 shell colors gnuplot

我用 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/

相关文章:

reactjs - 如何为缓冲区几何中的每个顶点分配不同的颜色?三.js

linux - 从 ps -ef |grep 关键字获取 pid

c# - 不着色,但 "Colorize" Sprite

macos - 操作系统 : Execute bash script when file appears in folder

javascript - 目标类元素而不是带有闪烁动画脚本的文档主体

2d - 如何在带有图像的 2D 图上绘制 mask (图案填充)- gnuplot

graph - gnuplot:在一个字符串列中绘制具有基于颜色的值的点,并在图例中显示字符串

gnuplot - 使用 gnuplot 输出带有抽动标签且没有任何边距/填充的图?

linux - 如何设置启动时init的资源限制?

shell - 如何在 Jenkins Build Execute Shell 中运行 docker 命令