在一周中的特定一天开始绘图

发布于 2024-10-17 17:14:48 字数 1665 浏览 1 评论 0原文

我正在通过处理每月文件中的潮汐数据来学习 gnuplot,格式如下:

2011/03/01  Tue 08:42   9.39    H
2011/03/01  Tue 15:04   0.2     L
2011/03/01  Tue 21:18   8.67    H
2011/03/02  Wed 03:16   0.71    L
2011/03/02  Wed 09:31   9.51    H
2011/03/02  Wed 15:49   0.09    L
2011/03/02  Wed 22:01   8.91    H
2011/03/03  Thu 04:01   0.48    L
2011/03/03  Thu 10:14   9.58    H
2011/03/03  Thu 16:28   0.05    L
2011/03/03  Thu 22:39   9.11    H

到目前为止一切都很好:我可以使用多图布局设置将堆叠图输出到 PDF 中,但我希望每周图始终运行周一至周日。

对于小数周,尤其是第一周,我该怎么做?我可以手动设置 xrange,但需要为每个每周的绘图命令重新完成。

我想弄清楚的是两件事:

  • 解决第一周问题的方法;
  • 一种在接下来的每一周自动执行 xrange 的方法(即,让 gnuplot 解析时间戳并每周一开始一个新的绘图?我可以使用三元运算符来执行此操作吗?)

设置:
gnuplot:版本 4.4 补丁级别 2
OSX 10.6.6

设置和绘图命令:

set timefmt "%Y/%m/%d-%H:%M"
set origin 0,0
set xdata time
unset key
set samples 1000
myDate(col1,col3)=sprintf("%s-%s",strcol(1),strcol(3))
set grid noxtics
set xtics nomirror font "Arial,10" tc rgb "blue"
set xtics offset 0,0  # required for position of tic labels when stacked.
set yrange [-3:13] 
set ytics 3
set grid ytics back
set x2data time
set x2tics 86400
set grid x2tics back
set x2tics 86400
set format x2 "%d"    # displays number of day of month
set x2tics offset 3.5,-3 font "Helvetica,20"    # required for position of numbers when stacked.
#### set size 1,.2    # un-comment for setting up stacked layout.
set tmargin 3   # gives adequate room between each row of days + labels.
set lmargin 5
set bmargin 2
set rmargin 2
plot 'MonthlyTideDataMarch.txt' u (myDate(1,3)):4:xticlabels(strcol(4) . " \n" . strcol(3) ) lc rgb "green" lw 3 sm cspl notitle

I'm learning gnuplot by working on tidal data, in monthly files, in this format:

2011/03/01  Tue 08:42   9.39    H
2011/03/01  Tue 15:04   0.2     L
2011/03/01  Tue 21:18   8.67    H
2011/03/02  Wed 03:16   0.71    L
2011/03/02  Wed 09:31   9.51    H
2011/03/02  Wed 15:49   0.09    L
2011/03/02  Wed 22:01   8.91    H
2011/03/03  Thu 04:01   0.48    L
2011/03/03  Thu 10:14   9.58    H
2011/03/03  Thu 16:28   0.05    L
2011/03/03  Thu 22:39   9.11    H

All is well so far: I can output stacked plots into PDF with the multiplot layout setup, BUT I'd like to have the weekly plots always run Monday-Sunday.

With fractional weeks, especially the first week, how can I do this? I can set the xrange manually, but it would need to be re-done for each weekly plot command.

What I'd like to figure out is two things:

  • a way to handle the first week problem;
  • a way to automate the xrange for each succeeding week (i.e., have gnuplot parse the timestamp and start a new plot each Monday? Can I perhaps do this using the ternary operator?)

Setup:
gnuplot: version 4.4 patchlevel 2
OSX 10.6.6

Setup & plot commands:

set timefmt "%Y/%m/%d-%H:%M"
set origin 0,0
set xdata time
unset key
set samples 1000
myDate(col1,col3)=sprintf("%s-%s",strcol(1),strcol(3))
set grid noxtics
set xtics nomirror font "Arial,10" tc rgb "blue"
set xtics offset 0,0  # required for position of tic labels when stacked.
set yrange [-3:13] 
set ytics 3
set grid ytics back
set x2data time
set x2tics 86400
set grid x2tics back
set x2tics 86400
set format x2 "%d"    # displays number of day of month
set x2tics offset 3.5,-3 font "Helvetica,20"    # required for position of numbers when stacked.
#### set size 1,.2    # un-comment for setting up stacked layout.
set tmargin 3   # gives adequate room between each row of days + labels.
set lmargin 5
set bmargin 2
set rmargin 2
plot 'MonthlyTideDataMarch.txt' u (myDate(1,3)):4:xticlabels(strcol(4) . " \n" . strcol(3) ) lc rgb "green" lw 3 sm cspl notitle

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坏尐絯℡ 2024-10-24 17:14:48

我将为此使用 bash 脚本并使用“日期”程序。您可能需要调整日期格式等,但原则上是这样;)这应该可行...

# write dates into a temporary file, create a date range
# for each line in your input file
echo -n ""> tmp.out
while read line; do
      d=${line:0:22}
      y=$(date --date "$d" +%Y)
      w=$(date --date "$d" +%W)
      M=$(date --date "$y-01-01 +$w weeks -1 week +2 day" +%Y-%m-%d)
      S=$(date --date "$y-01-01 +$w weeks -1 week +8 day" +%Y-%m-%d)
      echo '"'$M'":"'$S'"' >> tmp.out
done < data.txt

# make them unique
uniq tmp.out > dates.out

# create a gnuplot input file, needs your code from above
cat <<EOF > in.gnu
reset
EOF

# add a plot command for each date range. 
# needs your plot command and perhaps more plot specific data (title, etc.)
while read line; do
   cat <<EOF >>in.gnu
   set xrange [$line]
   plot "data.txt" u 1:2
EOF
done < dates.out

该脚本会生成一个 gnuplot 输入文件,然后您可以在数据上运行该文件。

I would use a bash script for this and use the "date" program. You probable need to tweak the date formats, etc., but in principle;) this should work...

# write dates into a temporary file, create a date range
# for each line in your input file
echo -n ""> tmp.out
while read line; do
      d=${line:0:22}
      y=$(date --date "$d" +%Y)
      w=$(date --date "$d" +%W)
      M=$(date --date "$y-01-01 +$w weeks -1 week +2 day" +%Y-%m-%d)
      S=$(date --date "$y-01-01 +$w weeks -1 week +8 day" +%Y-%m-%d)
      echo '"'$M'":"'$S'"' >> tmp.out
done < data.txt

# make them unique
uniq tmp.out > dates.out

# create a gnuplot input file, needs your code from above
cat <<EOF > in.gnu
reset
EOF

# add a plot command for each date range. 
# needs your plot command and perhaps more plot specific data (title, etc.)
while read line; do
   cat <<EOF >>in.gnu
   set xrange [$line]
   plot "data.txt" u 1:2
EOF
done < dates.out

the script generates a gnuplot input file that you can then run on your data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文