【问题标题】:Gnuplot, skipping timedat tics, histogramGnuplot,跳过时间数据,直方图
【发布时间】:2017-05-11 20:06:50
【问题描述】:

所以,我需要按日期制作数据直方图,但我遇到了 xticlabel 重叠的问题,所以,我试图找到一个解决方案,如何跳过 xtics 以避免重叠。考虑到日期不是整数抽动,我试图以这种方式解决它:

.dat 文件

Time    Dat 1   Dat 2
1   27-12-2016  12  2
2   28-12-2016  13  7
3   29-12-2016  17  2
4   30-12-2016  9   10
....

是否可以按第一列计算 xtic,但在第二列中显示值而不是在第一列中显示值?

我的代码:

reset
dx=5.
n=2
total_box_width_relative=0.75
gap_width_relative=0.1
d_width=(gap_width_relative+total_box_width_relative)*dx/2.
d_box = total_box_width_relative/n
reset

set term png truecolor font "arial,10" fontscale 1.0 size 800,400
set output "test.png"
set datafile separator "\\t"
set title "Errors"
set print "-"
set xlabel 'x' offset "0", "-1"
set ylabel 'y' offset "1", "-0"
set key invert reverse Left outside 
set key autotitle columnheader
set key samplen 4 spacing 1 width 0 height 0 
set autoscale yfixmax
set yrange [0: ]
set xtics strftime('%d-%m-%Y', "27-12-2016"), 5, strftime('%m-%d-%Y', "15-01-2017")  
set xtics font ", 7" 
set ytics auto font ", 9" 
set y2tics auto font ", 9"
set grid
set style data histogram
set style histogram cluster gap 1
set style fill transparent solid 0.75 noborder
set boxwidth 0.9 relative
set xtic rotate by -45 scale 0
plot 'datfile' u 3:xtic(strftime('%d-%m-%Y', strptime('%m.%d.%Y', stringcolumn(2)))), '' u 4

【问题讨论】:

  • 这不应该是对您其他问题的编辑吗?简单的plot 'datfile' u 3:xtic(1) 怎么样?然后删除所有你不需要的东西,应该超过所有行的一半
  • @Christoph s018.radikal.ru/i525/1612/4a/d98226528e84.png - 这就是我正在与之抗争的。我想跳过一些带间隔的 xlabel。以及如何做到这一点? Timedat 操作适用于盒子,但它们会覆盖每个 col 的每个盒子,这就是我不想要的,所以这就是我需要直方图而不是盒子的原因。
  • @Christoph BTW 我将它与 perl 一起使用以将变量封装到脚本列表中并进行一些操作,但它仅解决了 gnuplot 的部分问题。

标签: gnuplot histogram time-format


【解决方案1】:

在问这样一个模糊的问题之前,请始终将脚本减少到重现问题所需的最低限度。

在删除所有不必要的东西并修复 plot 命令后,这是我的最终结果:

reset
set datafile separator "\t"
set yrange [0:*]
set style fill transparent solid 0.75 noborder
set boxwidth 0.9 relative
set xtic rotate by -45 scale 0
set key autotitle columnheader

set style data histogram
set style histogram cluster gap 1

plot 'file.dat' using 3:xtic(2) t col(2), '' using 4

在这里,您已经看到了一种通过旋转来避免较长 tic 标签重叠的选项。

另一种可能性是跳过每个第 n 个 xticlabel。此时您必须了解 gnuplot 如何创建直方图。直方图不使用传统的数字轴,因此您不能像通常在绘制线条时那样简单地使用日期。但是 gnuplot 将每个条形簇放在一个整数 x 位置,例如xtic(2) 您使用第二列中给出的字符串标记每个集群。

表达式xtic(2)xticlabel(2) 的缩写,表示xticlabel(stringcolumn(2))。您可以在这里使用任何产生字符串的表达式,包括条件,而不是完全使用第二列中的字符串。仅绘制每隔一个标签检查行号是偶数还是奇数 int($0) % 2 == 0 并使用空字符串或第二列中的字符串:

plot 'file.dat' using 3:xtic(int($0)%2 == 0 ? stringcolumn(2) : '') t col(2), '' u 4

【讨论】:

  • 谢谢你,你救了我的神经。我一直在与这漫长的斗争。
  • 特别感谢您的完整解释,让我更好地理解 xtic() 的含义/作用
猜你喜欢
  • 2016-02-07
  • 1970-01-01
  • 1970-01-01
  • 2017-06-22
  • 2013-07-28
  • 1970-01-01
  • 2017-08-25
  • 2016-05-27
  • 1970-01-01
相关资源
最近更新 更多