如何将 X 轴设置为我的 SQL 提取临时文件中的日期?

how to set X axis as dates from my SQL extraction temporary file?

经过多次阅读后,我的用例无法正常工作
我暂时不明白为什么。

我的摘录看起来像这样:

 111 | 98.2 | 2020-07-11
 112 | 99.2 | 2020-07-15
 113 | 98.7 | 2020-07-25
 122 | 99.2 | 2020-07-26
 123 | 99.7 | 2020-07-27
 124 | 97.8 | 2020-07-28

& 我的 gnuplot 代码看起来像:

gnuplot --persist << EOF || ( exit 3 ) 
set xlabel "temps"
set ylabel "poid"
set terminal GNUTERM background rgb 'grey' size 1024,768
set grid ls 12
set sample 1000
set datafile separator "|"
set yrange [95:100]
set title "SUIVI POID"
set autoscale
plot "poid" with lines smooth bezier , "regime" with lines lt rgb "red" , "objectif" with lines smooth bezier lt rgb "white"
set terminal png
set output 'poid.png'
replot
pause mouse close
EOF

这样做我有我的曲线和体重等... 但是我有 111 , 112 , ... , 124 个值作为 X 标签

我尝试按日期替换:像那样(添加几行集合) :

set autoscale
set xdata time
set timefmt "%d/%m"
set format x "%b %d"
set xrange ["04/07":"31/12"]
set xtics "04/07",172800,"31/12"
plot "poid" with lines smooth bezier , "regime" with lines lt rgb "red" , "objectif" with lines smooth bezier lt rgb "white"
set terminal png

并得到那个错误:

gnuplot> plot "poid" with lines smooth bezier , "regime" with lines lt rgb "red" , "objectif" with lines smooth bezier lt rgb "white"
                                              ^
         line 0: Need full using spec for x time data

我围绕这个问题尝试了很多方法,但都失败了。我阅读了很多论坛解决方案,但似乎没有一个与我的问题相符 (我也误解了一些解决方案)

我想要日期作为 X 标签

你很接近,主要问题是你没有正确声明日期格式,timefmt 应该表示数据中日期的格式,你可以设置 xrange 使用相同的格式,那么您可以使用 using 3:2 绘图来告诉 gnuplot 使用第 3 列作为 x 坐标,使用第 2 列作为 y 坐标。

对您的脚本进行此调整

set xlabel "temps"
set ylabel "poid"
set object rectangle from screen 0,0 to screen 1,1 behind fillcolor rgb 'grey' fillstyle solid noborder
set grid ls 12
set sample 1000
set datafile separator "|"
set yrange [95:100]
set title "SUIVI POID"
set autoscale
set autoscale
set xdata time
set timefmt "%Y-%m-%d"
set format x "%b %d"
set xrange ['2020-07-11':'2020-07-28']
plot "test.txt" u 3:2  with lines smooth bezier

我从您发布的样本数据摘录中得到了这个图。

PD。 qt 终端没有背景 属性,所以我在所有内容后面使用了一个矩形。