我一直在寻找一段时间,以找出如何从财务图中删除一周中的几天,但没有成功。
我需要情节只包括一周中的几天,完全错过周末,这样财务图表中就没有 2 天的差距。
我有 CSV 格式的数据 Open/Low/Close/High 并且缺少周末数据,它绘制得很好,但我找不到如何不显示周末,任何帮助将不胜感激。
我想在 X 上看到它基本上是 M/T/W/T/F/M/T/W/T/F 而不是 M/T/W/T/F/S/S/M 等。 ..
干杯,
克里斯。
As far as I know, this cannot be done with gnuplot itself - you need to bring the file into the desired shape before. If you are on Linux, this can be done with something like
awk '{if( index( $1, "S" ) == 0 ) print $0 >> "new.dat"}' old.dat
where old.dat
is your original file and new.dat
the new file without weekends. I have assumed here that your data file has the weekday as the first entry in each line.
This would work under Windows as well, but you would need to install Gawk for Windows first.
数据未显示在文件中,该文件仅基于工作日并且错过了周末。如果你绘制数据,你会在周末得到这些 2 天的差距,所以我想消除这些差距。与周末的x轴更相关,以使其成为线性。
以下是部分文件的示例:
2006-03-23T16:59 1.7470 1.7324 1.7471 1.7344 0.0000 0.0000 0.0000 0.0000
2006-03-24T16:59 1.7346 1.7308 1.7441 1.7428 0.0000 0.0000 0.0000 0.0000
2006-03-27T17:59 1.7424 1.7415 1.7492 1.7459 0.0000 0.0000 0.0000 0.0000
2006-03-28T17 :59 1.7462 1.7422 1.7537 1.7424 0.0000 0.0000 0.0000 0.0000
如果您查看日期,则文件中存在空白。应该有差距,因为这些天没有数据。然而,该图应该没有间隙地运行,这就是我想要实现的目标。
我今天刚遇到set xdtics
。我怀疑您是否仍在为此工作,但也许这对其他人会有所帮助...(请参阅help xdtics
)
使用一些外部工具(我相信我会为此编写一个 bash 或 python 脚本;这应该不难),您可以将周末的行(一天一行)插入到您的数据文件中,如下所示:
2006-03-26T00:00 NaN NaN NaN NaN NaN NaN NaN NaN
(或者您可以NaN
在数据文件末尾附加那些周末的 s 并使用unique
关键字)
然后绘制,比方说,第一个数据using 1:($2) with linespoints
,而不是 using 1:2 ...
这应该适合你。
假设您的数据文件没有丢失任何工作日,您可以将日期列视为字符串类型。(如果您错过了工作日,您的图表将跳过这些日期而不为它们分配任何空间,这很容易错过,所以要小心。)
YYYY-MM-DD
我有一个日期作为我的数据文件格式的第一列。我正在绘制的数据在第二列。以下是我的 gnuplot 配置的相关行:
set format x '%s'
plot 'file' using 0:2:xtic(substr(strcol(1),6,10))
该set format
行告诉 gnuplot 如何打印 x 标签。配置使用第using
0 列(索引)作为 x 参数,第 2 列(数据)作为 y 参数,并提供打印标签的特殊说明:仅打印字符 6-10。(这切断了年份部分,这有助于标签在我的情况下不重叠。)
另请参阅此 SO 答案。我不想在每个周末都复制这种“断轴”解决方案,但也许它可以起到启发作用。