如何在 Gnuplot 中绘制带有标签和颜色的点?
How to plot points with label and color in Gnuplot?
我想在 Gnuplot 中用单独的标签和颜色绘制点。
我有一个数据文件a.dat
:
###label x y z
1 244.8 18 6.1
2 248.0 10.4 7
3 294.4 6.3 13.7
4 248.0 7.5 8.92
5 240.0 3.69 6.61
6 240.48 3.69 8.92
7 256 5.7 15.8
8 256 7 10.6
9 256 4.1 8.2
10 256 5.1 12.3
以下命令有效。
splot 'a.dat' using 2:3:4:1 with labels
set palette model RGB defined (0 'black',1 'blue', 2 'green', 3 'red')
splot 'a.dat' using 2:3:4:(==3?1:==6?2:==9?3:0) with points palette
但是我怎样才能混合它们呢?
假设我正确理解了你的问题,如果你只想为几个特定的点设置几种特定的颜色,你真的需要一个调色板吗?
您正在使用两种绘图样式 with points
和 with labels
您可以将它们组合在一个绘图命令中。
代码:
### variable color points
reset session
$Data <<EOD
###label x y z
1 244.8 18 6.1
2 248.0 10.4 7
3 294.4 6.3 13.7
4 248.0 7.5 8.92
5 240.0 3.69 6.61
6 240.48 3.69 8.92
7 256 5.7 15.8
8 256 7 10.6
9 256 4.1 8.2
10 256 5.1 12.3
EOD
myColor(col) = column(col)==3 ? 0x0000ff : \
column(col)==6 ? 0x00ff00 : \
column(col)==9 ? 0xff0000 : 0
set key noautotitle
splot $Data u 2:3:4:(myColor(1)) w p pt 7 lc rgb var, \
'' u 2:3:4:1 w labels offset 0.0,0.7,0.7
### end of code
结果:
加法:(彩色标签)
如果你想要有颜色的标签,那么改变绘图命令如下:
splot $Data u 2:3:4:1:(myColor(1)) w labels tc rgb var
嗯,你必须决定:
- 仅使用标签可能难以找到数据点的确切位置
- 使用没有偏移的点和标签可能难以读取数字
结果:(没有点的彩色标签)
我想在 Gnuplot 中用单独的标签和颜色绘制点。
我有一个数据文件a.dat
:
###label x y z
1 244.8 18 6.1
2 248.0 10.4 7
3 294.4 6.3 13.7
4 248.0 7.5 8.92
5 240.0 3.69 6.61
6 240.48 3.69 8.92
7 256 5.7 15.8
8 256 7 10.6
9 256 4.1 8.2
10 256 5.1 12.3
以下命令有效。
splot 'a.dat' using 2:3:4:1 with labels
set palette model RGB defined (0 'black',1 'blue', 2 'green', 3 'red')
splot 'a.dat' using 2:3:4:(==3?1:==6?2:==9?3:0) with points palette
但是我怎样才能混合它们呢?
假设我正确理解了你的问题,如果你只想为几个特定的点设置几种特定的颜色,你真的需要一个调色板吗?
您正在使用两种绘图样式 with points
和 with labels
您可以将它们组合在一个绘图命令中。
代码:
### variable color points
reset session
$Data <<EOD
###label x y z
1 244.8 18 6.1
2 248.0 10.4 7
3 294.4 6.3 13.7
4 248.0 7.5 8.92
5 240.0 3.69 6.61
6 240.48 3.69 8.92
7 256 5.7 15.8
8 256 7 10.6
9 256 4.1 8.2
10 256 5.1 12.3
EOD
myColor(col) = column(col)==3 ? 0x0000ff : \
column(col)==6 ? 0x00ff00 : \
column(col)==9 ? 0xff0000 : 0
set key noautotitle
splot $Data u 2:3:4:(myColor(1)) w p pt 7 lc rgb var, \
'' u 2:3:4:1 w labels offset 0.0,0.7,0.7
### end of code
结果:
加法:(彩色标签)
如果你想要有颜色的标签,那么改变绘图命令如下:
splot $Data u 2:3:4:1:(myColor(1)) w labels tc rgb var
嗯,你必须决定:
- 仅使用标签可能难以找到数据点的确切位置
- 使用没有偏移的点和标签可能难以读取数字
结果:(没有点的彩色标签)