te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>gnuplot - How to plot connected points from separated data blocks within a file? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

gnuplot - How to plot connected points from separated data blocks within a file? - Stack Overflow

programmeradmin2浏览0评论

The following data file can contain several blocks TP1, TP2, ..., TPn. How can I connect the points of each first, second, third, ... line with linespoint a diagram?

Example

first plotted line:

TP1 -> (37.74, 7030.26)
TP2 -> (26.42, 7652.64)
...

second plotted line:

TP1 -> (37.74, 7030.26)
TP2 -> (33.14, 7705.56)
...
reset 

GROUP_LABELS    = "1 2 3"
n_group_labels  = words(GROUP_LABELS)
in_group        = '( $1 == int(word(GROUP_LABELS, i)) ? 1.0 : NaN )'

$Data << EOD
# TP1
gp   HS   Age     vol_01    vol_02
2    0    37.74   7030.26   7353.44
2    0    26.42   7652.64   8566.62
2    0    30.20   6938.74   7489.41
2    0    27.68   6619.97   6224.74
2    1    18.87   7472.23   8635.48
2    0    34.56   6612.52   7347.70
2    0    33.54   7049.64   7137.09
3    1    21.47   8327.11   8745.67
1    0    22.00   7924.66   8694.33
1    0    24.96   7605.58   8072.01
3    1    12.10   8883.32   9230.87
2    0    24.72   8271.73   8465.82


# TP 2
gp   HS   Age     vol_01    vol_02
2    0    38.84   7069.54   7380.43
2    0    33.14   7705.56   8076.87
2    0    39.78   7346.33   7712.80
2    0    28.98   6963.54   7171.83
2    1    23.71   6830.13   8113.97
2    0    39.93   7438.96   7020.43
2    0    44.92   6943.02   7204.57
3    1    26.82   8245.33   8335.07
1    0    24.93   7396.14   7853.01
1    0    29.79   7421.25   7810.83
3    1    14.55   8672.95   8937.76
2    0    27.30   8668.11   8506.81



EOD

plot 0 lw 1 lc -1 notitle, \
    for [i=1:n_group_labels] $Data using ( @in_group * column(3)):(column(4)) w lp pt 7 ps 2 lc i 

The following data file can contain several blocks TP1, TP2, ..., TPn. How can I connect the points of each first, second, third, ... line with linespoint a diagram?

Example

first plotted line:

TP1 -> (37.74, 7030.26)
TP2 -> (26.42, 7652.64)
...

second plotted line:

TP1 -> (37.74, 7030.26)
TP2 -> (33.14, 7705.56)
...
reset 

GROUP_LABELS    = "1 2 3"
n_group_labels  = words(GROUP_LABELS)
in_group        = '( $1 == int(word(GROUP_LABELS, i)) ? 1.0 : NaN )'

$Data << EOD
# TP1
gp   HS   Age     vol_01    vol_02
2    0    37.74   7030.26   7353.44
2    0    26.42   7652.64   8566.62
2    0    30.20   6938.74   7489.41
2    0    27.68   6619.97   6224.74
2    1    18.87   7472.23   8635.48
2    0    34.56   6612.52   7347.70
2    0    33.54   7049.64   7137.09
3    1    21.47   8327.11   8745.67
1    0    22.00   7924.66   8694.33
1    0    24.96   7605.58   8072.01
3    1    12.10   8883.32   9230.87
2    0    24.72   8271.73   8465.82


# TP 2
gp   HS   Age     vol_01    vol_02
2    0    38.84   7069.54   7380.43
2    0    33.14   7705.56   8076.87
2    0    39.78   7346.33   7712.80
2    0    28.98   6963.54   7171.83
2    1    23.71   6830.13   8113.97
2    0    39.93   7438.96   7020.43
2    0    44.92   6943.02   7204.57
3    1    26.82   8245.33   8335.07
1    0    24.93   7396.14   7853.01
1    0    29.79   7421.25   7810.83
3    1    14.55   8672.95   8937.76
2    0    27.30   8668.11   8506.81



EOD

plot 0 lw 1 lc -1 notitle, \
    for [i=1:n_group_labels] $Data using ( @in_group * column(3)):(column(4)) w lp pt 7 ps 2 lc i 
Share Improve this question edited 2 days ago Mark Rotteveel 109k227 gold badges156 silver badges220 bronze badges asked 2 days ago magfanmagfan 4073 silver badges9 bronze badges 3
  • I'm confused. Which point (row r) of which block b do you want to be connected with which point (row) of which block? From your example, I see b1r1 to b1r2 and b1r1 to b2r2. What does ... mean? b1r1 to b3r3 or something else? – theozh Commented 2 days ago
  • Actually, 26.42, 7652.64 is not from TP2. Do you maybe mean: connect all first, second, third, ... rows of each block? So, in your example this would be just two points connected (i.e. one segment from TP1 to TP2), but 12 of such segments? Please clarify! – theozh Commented 2 days ago
  • Sorry, the example was a copy of the wrong output. What I ultimately want to represent are the following points (b=block, r=row, c=column). Blocks are different time points, column 3 is the age of the patient, columns >3 are brain structure volumes and each row represents the data set of a single patient. I need graphs that show the change in volume over time for each patient individually. The points are c3,c4 in b1r1, b2r1, b3r1, b4r1 for patient_1; b1r2, b2r2, b3r2, b4r2 for patient_2 and so on. – magfan Commented 2 days ago
Add a comment  | 

1 Answer 1

Reset to default 1

gnuplot breaks a line in the graph if there are empty lines in the data. So, you have to get rid of the empty lines or play other "tricks".

If I now understood correctly after your comment, I would suggest the following:

  • get rid of the empty lines by plotting your data into another datablock $Data2
  • if your blocks have all the same size you can work with every (check help every)
  • get the variable color from column 1
  • optional: add some labels for the patient, i.e. row index depending on the number of header lines using only the first block of the original data
  • add a legend for the groups using keyentry (check help keyentry)
  • if your plot 0 was just to force the y-range going from zero, you could also do set yrange[0:]

Script:

### plot linespoints connected over blocks
reset session

$Data << EOD
# TP1
gp   HS   Age     vol_01    vol_02
2    0    37.74   7030.26   7353.44
2    0    26.42   7652.64   8566.62
2    0    30.20   6938.74   7489.41
2    0    27.68   6619.97   6224.74
2    1    18.87   7472.23   8635.48
2    0    34.56   6612.52   7347.70
2    0    33.54   7049.64   7137.09
3    1    21.47   8327.11   8745.67
1    0    22.00   7924.66   8694.33
1    0    24.96   7605.58   8072.01
3    1    12.10   8883.32   9230.87
2    0    24.72   8271.73   8465.82


# TP 2
gp   HS   Age     vol_01    vol_02
2    0    38.84   7069.54   7380.43
2    0    33.14   7705.56   8076.87
2    0    39.78   7346.33   7712.80
2    0    28.98   6963.54   7171.83
2    1    23.71   6830.13   8113.97
2    0    39.93   7438.96   7020.43
2    0    44.92   6943.02   7204.57
3    1    26.82   8245.33   8335.07
1    0    24.93   7396.14   7853.01
1    0    29.79   7421.25   7810.83
3    1    14.55   8672.95   8937.76
2    0    27.30   8668.11   8506.81
EOD

set table $Data2
    set datafile separator "\n" commentschar ""
    plot $Data u (strcol(1)) w table
    set datafile separator            # reset to default
    set datafile commentschar         # reset to default
unset table

stats $Data index 0 u 0 nooutput     # get length of block
GROUP_LABELS = "1 2 3"
N_g          = words(GROUP_LABELS)
N_h          = 1                     # number of header lines
N_p          = STATS_records - N_h   # number of patients in block
set key noautotitle

plot for [p=0:N_p-1] $Data2 every N_p+N_h::p+N_h u 3:4:1 w lp pt 7 ps 2 lc var, \
                     $Data index 0 u 3:4:($0+1-N_h) w labels right offset -1,0, \
     for [g=1:N_g] keyentry w lp pt 7 ps 2 lc g ti "group ".word(GROUP_LABELS,g)
### end of script

Result:

发布评论

评论列表(0)

  1. 暂无评论