带有月份名称的Gnuplot X轴 [英] Gnuplot X-Axis with Month Names

查看:67
本文介绍了带有月份名称的Gnuplot X轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据文件,其中的浮点时间列从零增加到某个较大的值.每个时间点都与一个数据点关联.

I have a data file in which a floating-point time column increases from zero to some large value. Each time-point is associated with a data point.

时间点也恰好对应于几个月,因此0=Jan, 1=Feb, ..., 11=Dec, 12=Jan, 13=Feb, ...

The time points also happen to correspond to months, such that 0=Jan, 1=Feb, ..., 11=Dec, 12=Jan, 13=Feb, ...

我想绘制此数据,以便在X轴上看到月份名称,而不是0-*.

I'd like to plot this data such that I see the month names on the X-axis instead of 0-*.

有没有办法做到这一点?

Is there a way to do this?

如果有帮助,我还可以在数据中预先生成月份名称.

If it's helpful, I can also pre-generate the month name in the data.

下面是样本数据,其中包括可能有用的月份名称.

Sample data, with the possibly-helpful month name included, follows.


#Time Month Data
0.01   Jan 0
0.055  Jan 0
0.2575 Jan 0
1.1687 Feb 0
1.9889 Feb 0
3.1037 Apr 0.00065915
3.2427 Apr 0.0035198
4.0656 May 0.03785
4.2134 May 0.041977
5.0032 Jun 0.049293
6.024  Jul 0.080957
7.0317 Aug 0.34284
7.9847 Aug 0.80902
8.0081 Sep 0.8149
8.9749 Sep 0.94009
9.0316 Oct 0.94389
9.9893 Oct 0.97967
10.058 Nov 0.97967
10.295 Nov 0.97967
11.125 Dec 0.97967
13.151 Feb 0.97967
13.696 Feb 0.97967
14.124 Mar 0.9797
15.119 Apr 0.97733

推荐答案

我的第一个想法是尝试使用timefmt偷偷摸摸的尝试,但是不幸的是,由于所有月份的长度都不相同,所以该方法不起作用您实际上在这里没有线性比例尺.我认为您能做的最好的事情就是手动指定tic:

My first thought was to try something sneaky with timefmt, but unfortunately, that doesn't work since all the months aren't the same length, so you don't actually have a linear scale here. I think the best you can really do is to specify the tics manually:

set xtics ("Jan" 0.5, "Feb" 1.5, "Mar" 2.5, ...)

这将调整抽芯,使其在范围上居中.如果您不想这样做,请改用整数值:

This adjusts the tics so that they are centered on the range. If you don't want that, then use integer values instead:

set xtics ("Jan" 0, "Feb" 1, "Mar" 2, ...)

当然,您可以使用gnuplot 4.6中引入的for do循环使此操作更加灵活:

Of course, you can make this a little more flexible using a for do loop which was introduced in gnuplot 4.6:

MONTHS="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
set xtics ( "Jan" 0.5 )  #first one can't have `add`.
do for [i=1:15] {
    which_month = word(MONTHS,i%12+1)
    pos = i+0.5
    set xtics add ( which_month pos )
}
plot 'test.dat' u 1:3

您甚至可以通过stats命令查看STATS_max来获得循环的上限-(您可能会使用N = int(STATS_max+1)或类似名称):

You could even get the upper bound for your looping via the stats command looking at STATS_max -- (you'd probably use N = int(STATS_max+1) or something similar):

stats 'test.dat' u 1 nooutput #Runs stats on the file, generates STATS_max

还有一种简写形式也可以与gnuplot 4.4一起使用:

There's also a shorthand notation which works with gnuplot 4.4 too:

MONTHS="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
set xtics ( "Jan" 0.5 )
set for [i=1:15] xtics add ( word(MONTHS,i%12+1) i+0.5 )
plot 'test.dat' u 1:3

这篇关于带有月份名称的Gnuplot X轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆