有没有办法在 x 轴上以小时为单位绘制一天的变化?

发布于 2024-10-03 09:28:23 字数 348 浏览 1 评论 0原文

我正在使用 gnuplot 来绘制与时间相关的数据。

大约每 5 分钟取样一次,我有 200 个样本。

我用 x 轴格式绘制这些数据。

set format x "%H:%M"

理想情况下,我想在 x 轴穿过午夜时打印日期...但当它穿过午夜时。比如:

22:00   22:30   23:00   23:30   00:00   00:30   01:00
                              2010-11-17

任何 gnuplot 专家都知道如何做到这一点吗?

I'm using gnuplot to plot time-dependent data.

The samples are taken every 5 minutes or so and I have 200 samples.

I plot these with the x axis formatted to

set format x "%H:%M"

Ideally, I'd like to print the date whenever the x-axis crosses midnight... but only when it crosses midnight. Something like:

22:00   22:30   23:00   23:30   00:00   00:30   01:00
                              2010-11-17

Any gnuplot gurus out there know a way to do this?

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

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

发布评论

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

评论(1

温柔嚣张 2024-10-10 09:28:23

这是一个好问题。

以下内容基于 t16web.lanl.gov/Kawano/gnuplot/plot4-e.html#5.12.

您基本上需要绘制数据两次,每个轴一次。
第二次绘制数据时,我将实际绘图移出范围(减去 1000),以便只绘制一张图。以下 shell 脚本生成数据并绘制它,如下图所示。

希望这是你想要的。

#!/bin/bash

echo "2010-11-17 13:30:01,1
2010-11-17 13:30:12,3.1
2010-11-18 13:30:23,2.1
2010-11-19 13:30:34,4" > two_axis.dat

gnuplot<<EOF
## Plot a second axis with the day rather than the time
## Based on example from http://t16web.lanl.gov/Kawano/gnuplot/plot4-e.html#5.12.

##  make a png file
set term png small
set output "two_axis.png"
## reduce the size of the main plot to allow for second axis
set size 1.0,0.8
set bmargin 0
set lmargin 3  # set space given to axis
## The data for the second plot will be set to be out of range,
##     Need to explicitly set range here.
set yrange [0:5] 

set multiplot

## Main plot, raised slightly
set origin 0,0.2
set datafile separator "," 
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S" 
set format x "%H:%M" 

## Need to set xrange so that the axes of the two plots match exactly
set xrange["2010-11-17 12:00:00":"2010-11-19 14:00:00"]

## The main plot!
plot "./two_axis.dat" using 1:2 with lines

## Now want to draw second axis with just the days
set origin 0,0.1
## Dont want any ytics or minor xtics or drawn axes
set noytics
unset mxtics
unset border
## Don't want axis mirrored, want tick scales to zero so that it vanishes,
##    And some format for the days of the week axis
set xtics nomirror scale 0 format "%Y-%m-%d"

##  Specify the tics interval in seconds 1 day = 86400 seconds
set xtics "2010-11-01 00:00:00", 86400,   "2010-12-01 00:00:00"

## Replot the graph but this time with the data shifted out of the way,
##  we don't want to replot the data (difficult to align with previous plot) - 
##  we just want the axis
plot "./two_axis.dat" using 1:(\$2-1000) with lines notitle

## clean up
unset multiplot
set output
set term pop
EOF

alt text

祝一切顺利,

汤姆

Its a good question.

The following is based on t16web.lanl.gov/Kawano/gnuplot/plot4-e.html#5.12.

You basically need to plot the data twice, once for each axis.
The second time I plot the data, I move the actual plot out of range (by subtracting 1000) so that only one plot is drawn. The following shell script generates the data and plots it as in the graph below.

Hope this is what you want.

#!/bin/bash

echo "2010-11-17 13:30:01,1
2010-11-17 13:30:12,3.1
2010-11-18 13:30:23,2.1
2010-11-19 13:30:34,4" > two_axis.dat

gnuplot<<EOF
## Plot a second axis with the day rather than the time
## Based on example from http://t16web.lanl.gov/Kawano/gnuplot/plot4-e.html#5.12.

##  make a png file
set term png small
set output "two_axis.png"
## reduce the size of the main plot to allow for second axis
set size 1.0,0.8
set bmargin 0
set lmargin 3  # set space given to axis
## The data for the second plot will be set to be out of range,
##     Need to explicitly set range here.
set yrange [0:5] 

set multiplot

## Main plot, raised slightly
set origin 0,0.2
set datafile separator "," 
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S" 
set format x "%H:%M" 

## Need to set xrange so that the axes of the two plots match exactly
set xrange["2010-11-17 12:00:00":"2010-11-19 14:00:00"]

## The main plot!
plot "./two_axis.dat" using 1:2 with lines

## Now want to draw second axis with just the days
set origin 0,0.1
## Dont want any ytics or minor xtics or drawn axes
set noytics
unset mxtics
unset border
## Don't want axis mirrored, want tick scales to zero so that it vanishes,
##    And some format for the days of the week axis
set xtics nomirror scale 0 format "%Y-%m-%d"

##  Specify the tics interval in seconds 1 day = 86400 seconds
set xtics "2010-11-01 00:00:00", 86400,   "2010-12-01 00:00:00"

## Replot the graph but this time with the data shifted out of the way,
##  we don't want to replot the data (difficult to align with previous plot) - 
##  we just want the axis
plot "./two_axis.dat" using 1:(\$2-1000) with lines notitle

## clean up
unset multiplot
set output
set term pop
EOF

alt text

All the best,

Tom

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