plot - 如何避免图中的点(y轴)?
问题描述
我有这张图。
我的代码:
xcoord(N) = (N)
ycoord(N) = (column(0)+1)
symbol(N) = strcol(N) ne "/" ? strcol(N) : "/"
array colors = [0xFF0000, 0x0000FF, 0xFFFF00, 0x00FF00, 0xC080FF]
array symbol = ["/", "5", "g", "3", "o"]
color(sym) = sum [i=1:5] (symbol[i] eq sym ? colors[i] : 0)
plot for [N=1:6] 'test.txt' using (xcoord(N)):(ycoord(N)):(symbol(N)):(color(strcol(N))) with labels tc rgb variable font ":Bold" notitle, \
for [N=1:6] 'test1.txt' using (xcoord(N)+6):(ycoord(N)):(symbol(N)):(color(strcol(N))) with labels tc rgb variable font ":Bold" notitle
set xrange [0:12]
set yrange [0:5]
set ytics ("D" 1, "A" 2, "Q" 3, "F" 4)
为了绘制图表,我阅读了两个文件。两个文件具有相同的 y 轴。如何删除积分?
测试.txt
# | 1 | 2 | 3 | 4 | 5 |
---|---|---|---|---|---|
D | / | / | 5 | / | G |
一种 | / | ○ | / | / | 5 |
问 | / | / | ○ | / | 5 |
F | / | / | 3 | G | 3 |
test1.txt
# | 6 | 7 | 8 | 9 | 10 |
---|---|---|---|---|---|
D | 5 | / | 5 | / | G |
一种 | / | ○ | / | G | 5 |
问 | / | ○ | ○ | / | 5 |
F | / | / | 3 | 5 | 3 |
解决方案
您告诉 gnuplot 在图中绘制 y-tic 标签,因为您从第 1 列循环到第 6 列。此外,您不必手动设置 ytics,您可以在 plot 命令中自动设置:ytic(1)
。如果您使用word()
(check help word
),您可以避免使用数组,并且代码甚至应该使用 gnuplot 4.x(没有数组)运行。顺便说一句,如果要设置范围和抽动,则必须在 plot 命令之前执行此操作。
代码:
### plotting colored labels
reset session
$Data1 <<EOD
# 1 2 3 4 5
D / / 5 / g
A / o / / 5
Q / / o / 5
F / / 3 g 3
EOD
$Data2 <<EOD
# 6 7 8 9 10
D 5 / 5 / g
A / o / g 5
Q / o o / 5
F / / 3 5 3
EOD
myColors = "0xff0000 0x0000ff 0xffff00 0x00ff00 0xc080ff"
myColor(i) = int(word(myColors,i))
mySymbols = "/ 5 g 3 o"
mySymbol(i) = word(mySymbols,i)
myColorLookup(s) = sum [i=1:5] (s eq mySymbol(i) ? myColor(i) : 0)
myOffset = 5 # x-offset between the two files
set key noautotitle
set offset 0.5, 0.5, 0.5, 0.5 # add some margin to the border
plot for [c=2:6] $Data1 u (c-1): 0:c:(myColorLookup(strcol(c))):ytic(1) w labels tc rgb var font ":Bold", \
for [c=2:6] $Data2 u (c-1+myOffset):0:c:(myColorLookup(strcol(c))) w labels tc rgb var font ":Bold"
### end of code
结果:
推荐阅读
- amazon-qldb - 在 QLDB 中查找已删除数据的历史记录
- python - 如何在列操作中找到字符串模式?
- php - 未定义变量:提交表单时的 conn
- r - 在平衡数据框中创建一个变量,该变量是另一列的转置
- php - 修复 CSV 标头的数组键
- angular - Angular 8:PatchValue 不能与 ChangeDetector 和 UpdateValue 一起使用
- machine-learning - Rapid Miner 中的 k-means 质心图实际上是什么意思(用外行的话来说)?
- nsis - 模拟标准 Windows 弹出消息 哔声
- c++ - boost 信号和槽不在不同的线程中工作(使用 boost::asio::io_service)
- javascript - 使用 Firebase 自动注销用户