当我set xdata
和附带的选项来区分xtics我的数据没有被绘制,但图形窗口本身显示正常。但是,不使用set xdata .... set timefmt
选项会绘制数据点,但标签间距太近。
这会产生正确的输出,但xtics太接近易读性Link to output:
set ylabel "% Change"
set logscale y
set yrange [0.9:2]
set ytics nomirror
set y2range [1:50]
set y2tics
set y2label "-List- Rank"
set xtics rotate
set xlabel "Date"
set title "-List- -Stock-"
set datafile separator "|"
#choose the svg terminal
set terminal svg size 1600,900 font "Bitstream Vera Sans, 12" linewidth 1
#pipe the output to a file
set output "| cat >./stock.svg"
plot "< sqlite3 db.sq3 'SELECT IBD50_CPRT_Master.Date, ...'" using
($2/31.8):xtic(1) with linespoints title "CPRT" , \
"< sqlite3 db.sq3 'SELECT IBD50_CPRT_Master.Date, ...'" using ($9/1472.33):xtic(1) with linespoints title "SP 500", \
"< sqlite3 db.sq3 'SELECT IBD50_CPRT_Master.Date, ... '" using ($3):xtic(1) axes x1y2 with points title "CPRT Rank"
这不会绘制数据点,但是xtics间隔清晰Link to output:
set ylabel "% Change"
set logscale y
set yrange [0.9:2]
set ytics nomirror
set y2range [1:50]
set y2tics
set y2label "-List- Rank"
set xtics rotate
set xlabel "Date"
set xdata time
set timefmt "%Y-%m-%d"
set format x "%Y-%m-%d"
set xtics nomirror
set xrange ["2013-01-16":"2014-04-23"]
#set the xtics to be one week (604800 seconds) apart for major tics
set xtics "2013-01-16",604800,"2014-04-23"
set title "-List- -Stock-"
set datafile separator "|"
#choose the svg terminal
set terminal svg size 1600,900 font "Bitstream Vera Sans, 12" linewidth 1
#pipe the output to a file
set output "| cat >./stock.svg"
plot "< sqlite3 db.sq3 'SELECT IBD50_CPRT_Master.Date, ...'" using
($2/31.8):1 with linespoints title "CPRT" , \
"< sqlite3 db.sq3 'SELECT IBD50_CPRT_Master.Date, ...'" using ($9/1472.33):1 with linespoints title "SP 500", \
"< sqlite3 db.sq3 'SELECT IBD50_CPRT_Master.Date, ... '" using ($3):1 axes x1y2 with points title "CPRT Rank"
我不确定gnuplot如何处理数据,因为我认为这可能是问题的一部分。数据点在星期一和星期三,但有时候星期一数据点可能在星期二。
以下是一段代码,您可以看到由于假期,星期一2/17数据点在2月18日。
2014-01-29|34.22||34.62|33.95|34.25|349000|34.25|1790.15|1790.15|1770.45|1774.2|3964020000|1774.2
2014-02-03|34.11||34.11|32.59|32.64|1438700|32.64|1782.68|1784.83|1739.66|1741.89|4726040000|1741.89
2014-02-10|33.84||34.03|33.56|33.94|416100|33.94|1796.2|1799.94|1791.83|1799.84|3312160000|1799.84
2014-02-12|34.69||34.86|34.46|34.73|746800|34.73|1820.12|1826.55|1815.97|1819.26|3326380000|1819.26
2014-02-18|34.25||34.43|33.75|33.81|1205200|33.81|1839.03|1842.87|1835.01|1840.76|3421110000|1840.76
2014-02-19|33.64||34.52|33.36|34.27|1085300|34.27|1838.9|1847.5|1826.99|1828.75|3661570000|1828.75
2014-02-24|34.82||35.57|34.72|35.36|1333400|35.36|1836.78|1858.71|1836.78|1847.61|4014530000|1847.61
2014-02-26|34.67||35.89|33.91|35.49|2035800|35.49|1845.79|1852.65|1840.66|1845.16|3716730000|1845.16
2014-03-03|36.26||36.43|35.83|36.16|467600|36.16|1857.68|1857.68|1834.44|1845.73|3428220000|1845.73
2014-03-05|36.56||36.83|36.3|36.78|431200|36.78|1874.05|1876.53|1871.11|1873.81|3392990000|1873.81
答案 0 :(得分:2)
绘图命令的第一个变体,即
plot "< sqlite3 ..." using ($2/31.8):xtic(1)
使用行号作为x值,并为x轴上的每个数据点放置一个标签,该标签取自第一列。
在第二种情况下,您使用时间数据作为y值,但它应该是using 1:($2/31.8)
。因此,完整的绘图命令可能如下所示:
plot "< sqlite3 db.sq3 'SELECT IBD50_CPRT_Master.Date, ...'" using 1:($2/31.8):1 with linespoints title "CPRT" , \
"" using 1:($9/1472.33):1 with linespoints title "SP 500", \
"" using ($3):1 axes x1y2 with points title "CPRT Rank"
""
使用与上一个绘图命令相同的源。
并且您不需要在任何地方输出输出,set output "stock.svg"
工作正常。