【问题标题】:How can I store and access matrix elements in gnuplot?如何在 gnuplot 中存储和访问矩阵元素?
【发布时间】:2015-02-17 08:30:52
【问题描述】:

我正在尝试制作 19x19 六边形格子,每个格子都包含一个圆柱体,其颜色不同,称为“hexagon.dat”。

2-> 红色圆柱体

1-> 用绿色着色的圆柱体

六边形.dat

2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2

但是目前,由于我不知道如何存储和访问hexagon.dat的矩阵数据,所以只有绿色圆柱体 这是我的 gnuplot 脚本

脚本

set term X11 persist title "test" size 1000, 1000

P = 0.78
pin_id = 0

do for [pin_ix=-9:9]{
do for [pin_iy=-9:9]{

cx = pin_ix*P + pin_iy*(-P/2)
cy = pin_iy*sqrt(3)/2*P
pin_id = pin_id + 1
set object pin_id poly from cx-P/2, cy+P/2/sqrt(3) \
                       to cx, cy+P/sqrt(3) \
                       to cx+P/2, cy+P/2/sqrt(3) \
                       to cx+P/2, cy-P/2/sqrt(3) \
                       to cx, cy-P/sqrt(3) \
                       to cx-P/2, cy-P/2/sqrt(3) \
                       to cx-P/2, cy+P/2/sqrt(3) \
fs solid fc rgb "red"


pin_id = pin_id + 1
set object pin_id circle at cx, cy size 0.3275 \
fs solid fc rgb "green"
}
}

set size ratio 1.0
set xr [-11:11]
set yr [-11:11]


plot 1/0

我在等待你的帮助。

【问题讨论】:

    标签: matrix gnuplot call store


    【解决方案1】:

    您可以使用plot ... with circles 绘制圆柱体。然后你可以用lc variable选择颜色:

    P = 0.78
    pin_id = 0
    
    do for [pin_ix=-9:9]{
    do for [pin_iy=-9:9]{
    
    cx = pin_ix*P + pin_iy*(-P/2)
    cy = pin_iy*sqrt(3)/2*P
    pin_id = pin_id + 1
    set object pin_id poly from cx-P/2, cy+P/2/sqrt(3) \
                           to cx, cy+P/sqrt(3) \
                           to cx+P/2, cy+P/2/sqrt(3) \
                           to cx+P/2, cy-P/2/sqrt(3) \
                           to cx, cy-P/sqrt(3) \
                           to cx-P/2, cy-P/2/sqrt(3) \
                           to cx-P/2, cy+P/2/sqrt(3) \
    fs solid fc rgb "red"
    
    
    pin_id = pin_id + 1
    }
    }
    
    set size ratio 1.0
    set xr [-11:11]
    set yr [-11:11]
    
    set style fill solid noborder
    set linetype 1 lc rgb 'red'
    set linetype 2 lc rgb 'green'
    plot 'hexagon.dat' matrix using (($1-9)*P + ($2-9)*(-P/2)):(($2-9)*sqrt(3)/2 * P):(0.3275):3 with circles lc variable 
    

    在 5.0 版本中,您可以使用 stats 来提取矩阵维度:

    stats 'hexagon.dat' matrix
    N = int(STATS_size_x)
    do for [pin_ix=-(N/2):((N-1)/2)] {
    ...
    

    【讨论】:

      【解决方案2】:

      新十六进制数据

      2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
      2 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2
      2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2
      2 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2
      2 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2
      2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2
      2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2
      2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2
      2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2
      2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
      2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
      2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
      2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
      2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2
      2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 2
      2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 2
      2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2
      2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 2
      2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
      

      脚本

      set term X11 persist title "test" size 1000, 1000
      P = 0.78
      pin_id = 0
      
      do for [pin_ix=-9:9]{
      do for [pin_iy=-9:9]{
      
      cx = pin_ix*P + pin_iy*(-P/2)
      cy = pin_iy*sqrt(3)/2*P
      pin_id = pin_id + 1
      set object pin_id poly from cx-P/2, cy+P/2/sqrt(3) \
                             to cx, cy+P/sqrt(3) \
                             to cx+P/2, cy+P/2/sqrt(3) \
                             to cx+P/2, cy-P/2/sqrt(3) \
                             to cx, cy-P/sqrt(3) \
                             to cx-P/2, cy-P/2/sqrt(3) \
                             to cx-P/2, cy+P/2/sqrt(3) \
      fs solid fc rgb "red"
      
      
      pin_id = pin_id + 1
      }
      }
      
      set size ratio 1.0
      set xr [-11:11]
      set yr [-11:11]
      
      set style fill solid noborder
      set linetype 1 lc rgb 'green'
      set linetype 2 lc rgb 'red'
      plot 'NewHexData' matrix using (($1-9)*P + ($2-9)*(-P/2)):(($2-9)*sqrt(3)/2 * P):(0.3275):3 with circles lc variable
      

      由于我没有足够的声誉,我无法上传生成的图像。 无论如何,我得到了这个数字。

      http://imgur.com/vEpjdll

      我真的很感谢克里斯托夫!

      【讨论】:

        猜你喜欢
        • 2014-07-17
        • 2022-10-24
        • 1970-01-01
        • 2013-02-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多