使用2D矩阵和自定义抽搐绘制单元格边框

时间:2018-06-15 21:22:18

标签: matrix grid gnuplot heatmap

我尝试关注this post 使用Gnuplot 绘制热图。

我有一个矩阵文件,包含27行和10列,我想绘制每个单元格的边框,如图1所示。'完成运行我用" Axis / Grid Settings"编写的代码。部分未注释。这在一开始就没问题,但我需要一些自定义xtics / ytics。我试图在我的代码中添加两行(Custom Settings部分),但它似乎弄乱了单元格边框(图2)。如何修改我的代码以使矩阵中的每个单元格具有这些自定义xtics / ytics以及分隔良好的边框?

提前谢谢!

数据文件:

380.3200 382.4620 292.6140 292.9600 282.2740 290.8940 292.8200 287.7200 286.8920 283.3660
336.9680 339.2540 264.0880 265.9060 257.1280 263.9120 277.0780 260.0020 262.7080 255.6500
334.4240 336.6840 265.9740 267.4800 254.5440 262.8280 273.2200 257.4620 280.6800 252.2840
358.9840 360.9980 310.9040 312.6040 299.3540 307.1200 362.2860 304.4560 325.7840 298.5620
347.1300 349.2180 289.2200 285.6600 284.1780 288.1480 329.2340 283.9640 280.8600 278.3040
322.6500 324.9480 265.3560 261.9380 244.9060 254.1940 266.9340 258.6980 258.5300 251.2160
426.7300 428.8280 436.4500 412.8840 383.2120 407.6080 532.2780 412.9500 419.1080 389.5320
416.5340 416.7240 438.2140 419.5780 403.4400 406.0380 517.2260 429.7320 426.9280 399.8540
393.6660 395.8460 387.6520 382.0320 375.5120 377.8640 468.4520 389.5580 386.2140 370.3540
427.1140 374.0700 431.1460 411.3860 371.9580 385.2440 444.5200 394.7540 397.8260 372.7000
373.9160 363.7280 376.4720 379.1140 400.4760 373.5220 386.5660 371.1000 368.3200 383.8900
417.1940 378.1160 419.9100 401.9080 382.3020 386.7600 428.0140 401.3220 398.3640 384.2340
358.4700 360.6560 360.4720 364.4440 389.1960 365.9380 360.8900 363.2520 363.5100 385.6520
360.8840 363.4000 362.8200 366.8500 403.9120 370.9180 363.5240 366.7940 367.3120 399.2460
355.4560 357.6320 357.5060 361.4680 403.7280 365.5100 357.7400 361.1640 360.0560 397.6960
357.3360 359.5200 359.2760 363.2800 394.8260 366.7920 359.8100 362.5560 362.5780 390.9120
355.8860 357.9080 357.9080 361.4340 407.3000 365.1860 357.7680 359.8660 360.2980 399.5420
354.7980 357.0280 356.8120 360.7980 387.4000 363.6140 357.2420 412.3720 360.0540 382.7100
354.3480 356.4500 356.3020 360.3320 400.9320 364.3640 356.5400 358.6600 361.5040 393.4020
360.8340 363.1740 362.8300 366.8300 392.3820 368.7060 363.1660 366.1580 365.8340 389.5200
358.1560 360.3400 360.1140 364.1460 398.6460 367.3400 360.4940 363.0660 388.2080 393.8640
367.2020 369.6460 369.1500 373.1680 385.3720 372.1040 367.8280 407.9380 373.5340 385.5020
363.3000 365.7260 365.3240 369.2740 402.7100 367.0980 365.7460 368.2980 369.0900 399.1380
357.9180 360.1700 359.9280 363.9160 390.8620 365.1240 360.4480 363.4620 363.8740 385.1540
372.3420 374.5400 374.3220 378.3420 397.7520 375.9460 372.6520 376.0120 374.3080 396.2340
359.9940 362.4520 362.0120 365.9940 377.8200 366.4480 361.6300 363.5540 379.2080 374.4260
369.1360 371.2940 371.0680 374.9980 367.1840 365.9320 368.5120 384.7140 370.9780 367.8480

Gnuplot代码:

set term postscript eps enhanced color font "Helvetica, 20"
set output '| epstopdf --filter --outfile=heatmap.pdf'
unset key

# Palette
set palette model HSV rgbformulae 3,2,2

# Size Ratio & Range
set size ratio 1.5
set autoscale fix
set cbrange[250:550]
set cbtics 50

# Titles
set title "Title"
set cblabel "CB" offset 1,0

# Axis/Grid Settings (Figure 1)
set xtics 1
set ytics 1
set mxtics 2
set mytics 2
set tics scale 0,0.001
set grid front mxtics mytics lw 2 lt -1 lc rgb 'white'

# Custom Settings (Figure 2)
#set xtics ("1" 0, "2" 1, "3" 2, "4" 3, "5" 4, "6" 5, "7" 6, "8" 7, "9" 8, "10" 9)
#set ytics ("A" 0, "B" 1, "C" 2, "D" 3, "E" 4, "F" 5, "G" 6, "H" 7, "I" 8, "J" 9, "K" 10, "L" 11, "M" 12, "N" 13, "O" 14, "P" 15, "Q" #16, "R" 17, "S" 18, "T" 19, "U" 20, "V" 21, "W" 22, "X" 23, "Y" 24, "Z" 25, "1" 26) font "Helvetica, 12"

# Plot
plot "datafile.dat" matrix w image notitle

Axis/Grid Settings & Custom Settings

1 个答案:

答案 0 :(得分:1)

通过指定显式tic标签,您可以关闭次要抽搐的生成。来自help mxtics

  

set m{x|x2|y|y2|z}tics命令仅在统一时才起作用    间隔主要抽搐。如果所有主要抽搐都明确放置    set {x|x2|y|y2|z}tics,然后忽略次要的tic命令。

在这种情况下,您必须手动设置次要标记:

  

要在任意位置设置次要抽搐,请​​使用(“”,    ...)set {x|x2|y|y2|z}tics的形式为空并设置为1。

这样的事情应该有效(在set ytics行之后添加这些命令):

do for [x=0:8] {set xtics add ("" x+0.5 1)}
do for [y=0:25] {set ytics add ("" y+0.5 1)}