即时更改X轴刻度

发布于 2025-02-01 21:26:44 字数 1220 浏览 2 评论 0原文

我正在使用以下GNUPLOT脚本来绘制一组文件的数据,这些文件每五分钟一次不断地添加到每五分钟:

set terminal x11 size 1900, 900
# The plot will not jump to the current window on update.
set term x11 1 noraise
set obj 1 rectangle behind from screen 0,0 to screen 1,1
set obj 1 fillstyle solid 1.0 fillcolor rgbcolor "black"
set grid lc rgb "white"

set key left top
set key textcolor rgb "white"

set border lc rgb "white"

set xtics textcolor rgb "white"
set xtics font "Times,12"
set xtics 1
set xlabel "Hours" textcolor rgb "white"

set ytics textcolor rgb "white"
set ytics font "Times,12"
set ytics 5
set ylabel "Hits" textcolor rgb "white"

set yrange [0:50]
set y2tics font "Times,10"
set y2tics 1                  # Figures on the right side of the plot as well
set y2range [0:50]

plot "/tmp/Stats/One" using ($1)/(12.):2 title "One" with lines, "/tmp/Stats/Two" using ($1)/(12.):2 title "Two" with lines, "/tmp/Stats/Three" using ($1)/(12.):2 title "Three" with lines
pause 300
reread

X轴中的抽动与小时间隔相对应。这可以正常工作,直到脚本运行一天左右 - 此时,X轴上的抽动开始看起来有些混乱。

是否可以从GNUPLOT脚本本身中动态更改此?这个想法是,如果脚本运行的时间超过半天,则X轴中的抽动应每两个小时而不是每小时出现一次。以及以后的其他类似更改 - 例如,一周后,每天应该有一个抽动。因此,文本标签必须更改。

gnuplot是否能够做到这一点,还是我们谈论的是壳脚本驱动的方法?后者显然是可能的,但这会更加麻烦。

I am using the following gnuplot script to plot data from a set of files that are being added to constantly, once every five minutes:

set terminal x11 size 1900, 900
# The plot will not jump to the current window on update.
set term x11 1 noraise
set obj 1 rectangle behind from screen 0,0 to screen 1,1
set obj 1 fillstyle solid 1.0 fillcolor rgbcolor "black"
set grid lc rgb "white"

set key left top
set key textcolor rgb "white"

set border lc rgb "white"

set xtics textcolor rgb "white"
set xtics font "Times,12"
set xtics 1
set xlabel "Hours" textcolor rgb "white"

set ytics textcolor rgb "white"
set ytics font "Times,12"
set ytics 5
set ylabel "Hits" textcolor rgb "white"

set yrange [0:50]
set y2tics font "Times,10"
set y2tics 1                  # Figures on the right side of the plot as well
set y2range [0:50]

plot "/tmp/Stats/One" using ($1)/(12.):2 title "One" with lines, "/tmp/Stats/Two" using ($1)/(12.):2 title "Two" with lines, "/tmp/Stats/Three" using ($1)/(12.):2 title "Three" with lines
pause 300
reread

The tics in the x axis correspond to hourly intervals. This works fine, until the script has been running for a day or so - at which point the tics in the x axis start to look a bit cluttered.

Would it be possible to change this dynamically from within the gnuplot script itself? The idea is that if the script has been running for more than, say, half a day, the tics in the x axis should be present once every two hours, rather than once every hour. And possibly other similar changes later on - e.g. after one week, there should be one tic per day. The text label would have to change consequently.

Is gnuplot capable of this, or are we talking about a shell script-driven approach instead? The latter is obviously possible, but it would be more cumbersome.

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

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

发布评论

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

评论(1

小伙你站住 2025-02-08 21:26:44

根据SO-RUL的“评论中无答案” ...

使用行设置XTICS 1您明确将XTIC间隔设置为1,
因此,不允许GNUPLOT自动确定哪个抽动间隔似乎是合理的。
检查帮助XTIC

删除行:

set xtics 1


替换为

set xtics auto

According to the SO-rule "no answer in comments"...

With the line set xtics 1 you are explicitely setting the xtic interval to 1,
hence not allowing gnuplot to automatically decide which tic interval seems reasonable.
Check help xtics.

Remove the line:

set xtics 1

or
replace it by

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