【问题标题】:GnuPlot: Data Format for Heat Map?GnuPlot:热图的数据格式?
【发布时间】:2021-07-06 15:36:13
【问题描述】:

我正在尝试在 GnuPlot 中制作热图。这是数据:

我得到了这个数据布局:

...但我必须将 Y 轴值四舍五入到最接近的 5 以使它们适合网格的确切行。

所以我试图找出一个更 3D 的数据布局。我尝试过这样的事情:

X    Y    Z
1   69  3.9

2   44  5.2

3   39  2.6

4   51  5.1

5   50  2.2

6   47  2.5

7   52  2.1

8   52  2.6

9   52  4.0

...但出现“LU-DECOMP 中的奇异矩阵”错误。

我尝试在数据文件中为每个 Z 值做多行,但我不知道为空的 X 和 Y 位置放置什么。

这样布置数据文件的正确方法是什么?

为了完整起见,这是我的命令文件:

unset surface
unset key
set view map
set pm3d
set palette defined (0 'black', 1 'gray40', 2 'dark-green', 3 '#fee000', 4 '#fc7a00', 5 '#ff0000')
set cbrange [0:5]
set output 'temp.jpg'

set term jpeg size 900, 900 enhanced font '/Library/Fonts/Arial.ttf' 12  #000000 Effffff
set dgrid3d 400,400 splines
set size square
set xtics("" 1, "X Label 1" 2, "X Label 2" 3, "X Label 3" 4, "X Label 4" 5, "X Label 5" 6, "X Label 6" 7, "X Label 7" 8, "X Label 8" 9, "X Label 9" 10)
unset label
unset title
set title '{/=18 Title}'  offset 0, .5
set ylabel '{/=18 Y Label}'  offset -1.6, 0
set xlabel '{/=18 X Label}'  offset 0,-3.0
set xtics out nomirror
set ytics out nomirror
set ytics("25" 0, "30" 1, "35" 2, "40" 3, "45" 4, "50" 5, "55" 6, "60" 7, "65" 8, "70" 9, "75" 10, "" 11)
set y2tics("25" 0, "30" 1, "35" 2, "40" 3, "45" 4, "50" 5, "55" 6, "60" 7, "65" 8, "70" 9, "75" 10, "" 11)

set xrange [0:11] 
set yrange [0:11]
unset colorbox 

set link x2; set link y2

splot [1:] '/gnuplot_data_test_v400.txt' matrix

replot


# http://hirophysics.com/gnuplot/gnuplot10.html
# https://stackoverflow.com/questions/17154364/gnuplot-pm3d-plot-triangle-data?rq=1
# https://askubuntu.com/questions/900501/i-cant-splot-with-pm3d-map-my-data-file-gnuplot
# http://lowrank.net/gnuplot/datafile-e.html#3dim
# http://psy.swansea.ac.uk/staff/carter/gnuplot/gnuplot_3d.htm


更新:这是我正在尝试制作的图表:

【问题讨论】:

    标签: 3d gnuplot heatmap


    【解决方案1】:

    我并不完全清楚您的确切期望是什么...,但我会使用绘图风格with boxxyerror(检查help boxxyerror)。

    代码:

    ### heatmap with boxxyerror
    reset session
    
    # X    Y    Z
    $Data <<EOD
    1   69  3.9
    2   44  5.2
    3   39  2.6
    4   51  5.1
    5   50  2.2
    6   47  2.5
    7   52  2.1
    8   52  2.6
    9   52  4.0
    EOD
    
    myXLabels = '"Label A" "Label B" "Label C" "Label D" "Label E" "Label F" "Label G" "Label H" "Label I"'
    myXtic(col) = word(myXLabels,int(column(col)))
    BoxWidth = 1
    BoxHeight = 1
    xLow(col)  = column(col)-BoxWidth/2.
    xHigh(col) = column(col)+BoxWidth/2.
    yLow(col)  = column(col)-BoxHeight/2.
    yHigh(col) = column(col)+BoxHeight/2.
    
    set style fill solid 1.0
    plot $Data u 1:2:(xLow(1)):(xHigh(1)):(yLow(2)):(yHigh(2)):3:xtic(myXtic(1)) w boxxy fc palette notitle
    ### end of code
    

    结果:

    加法:

    在不了解您的应用程序的详细信息的情况下,以下内容可能是一个起点。在 z=0 的角落添加一些点。您可能想“玩”set dgrid3d 200,200 gauss kdensity 1.5 行中的值。

    代码:

    ### heatmap with interpolation
    reset session
    
    # X    Y    Z
    $Data <<EOD
    1   69  3.9
    2   44  5.2
    3   39  2.6
    4   51  5.1
    5   50  2.2
    6   47  2.5
    7   52  2.1
    8   52  2.6
    9   52  4.0
    EOD
    
    # add some points in the corners with z=0
    set print $Data append
    do for [x=0:10:10] {
        do for [y=35:70:35] {
            print sprintf("%g %g %g",x,y,0)
        }
    }
    set print
    
    set view map
    set palette defined (0 'black', 1 'gray40', 2 'dark-green', 3 '#fee000', 4 '#fc7a00', 5 '#ff0000')
    set dgrid3d 200,200 gauss kdensity 1.5
    unset key
    set tics out
    
    splot $Data u 1:2:3 w pm3d
    ### end of code
    

    结果:

    【讨论】:

    • 感谢您的建议,@theozh。我已经用我正在尝试创建的图表类型的示例更新了原始帖子。有没有办法使用您提供的数据格式创建该图表?
    • @VikR 查看修改后的答案。这回答了你的问题了吗?但是,我会小心插值。在某些情况下,它可能给人的印象是有一些数据,尽管它可能只是一个插值伪影,例如问题中图中的垂直灰色“线”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-15
    • 2021-08-13
    • 1970-01-01
    • 2014-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多