在 gnuplot 中设置轴刻度标签
我对 gnuplot 的输入看起来像这样:
1:00am 1 10
1:00am 30 12
1:01am 60 18
1:01am 90 20
1:02am 120 21
...
第一列包含(我想要的)X 轴标签,而第二列包含 X 轴值。 (实际上,我每秒有一行,所以很多行都有“1:00am”,如标签列中所示,然后是“1:01am”,等等)。
我可以使用类似的方法绘制我关心的值:
gnuplot> plot "my_data.txt" using 2:3 with lines
我可以将 X 轴设置为每 30 分钟(即 30 * 60 = 1800 秒)有一个刻度(和标签),但它使用的标签是 X 轴值(大约 3600 一小时)。
我无法得到的是每个刻度下显示的标签使用第一列中的值。我什至在 gnuplot 手册中找不到任何看起来有希望的东西。我必须假设这是可能的,我只是不知道该去哪里寻找。
编辑:
进展,我发现了plot
的xticlabels()
参数。问题在于,它似乎为每个 xtic(即我的数据集中每秒一个)绘制这些标签,而不是按照 set xtics
定义的间隔绘制这些标签。
编辑和回答:
事实证明,gnuplot
支持绘制时间序列数据图形。出于好奇:
set timefmt "%H:%M:%S"
set xdata time
这会导致 X 轴数据(一旦重新格式化以匹配该模式)被解释为时间序列数据。 相结合。
set xtics 3600
然后将其与我所描述的设置 X 轴格式
My input to gnuplot looks something like this:
1:00am 1 10
1:00am 30 12
1:01am 60 18
1:01am 90 20
1:02am 120 21
...
The first column contains (what I'd like to be) the X-axis labels, while the second column contains the X-axis values. (In actual point of fact, I have one row per second, so many rows have '1:00am' as in the label column, then '1:01am', etc).
I can plot the values I care about using something like:
gnuplot> plot "my_data.txt" using 2:3 with lines
And I can set the X axis to have a tick (and label) every 30 minutes (which is 30 * 60 = 1800 seconds), but the label it uses is the X axis value (something like 3600 for one hour).
What I can't get is for the labels that show up under each tick to use the values from the first column. I can't even find anything that looks promising in the gnuplot manual. I've got to assume this is possible, I just don't know where to look.
Edit:
Progress, I've discovered the xticlabels()
parameter to plot
. The problem is that it seems to plot these labels for every xtic (that is, one per second in my data set), rather than at the intervals defined by set xtics
.
Edit and Answer:
Turns out gnuplot
has support for graphing time-series data. For the curious:
set timefmt "%H:%M:%S"
set xdata time
This causes the X axis data (once reformatted to match that pattern) to be interpreted as time-series data. This is then combined with
set xtics 3600
Formats the X axis as I described.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉这么晚了,但是是的,建议
set timefmt ... ;设置xdata时间
。我总是以%s
的形式传递时间格式,但这只是一种常见做法。Sorry caught this late, but yes was to suggest
set timefmt ... ; set xdata time
. I always pass in my time format as%s
but just as a common practice.