0
votes

I am plotting some data and I am getting multiple lines streaking across the plot. There should be one line, so I imagine that gnuplot is trying to fit the data and is joining points or something in a strange way. How can I get gnuplot to plot one like instead of multiple lines? Here is my script:

set term png font 'Liberation Sans,10' size 800,200
set output "data/values.png"
set style line 1 lt 1 lw 1 lc rgb "purple" pt -1
set xlabel "Time" font 'Liberation Sans,10'
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set xtics font 'Liberation Sans,10'
set ytics font 'Liberation Sans,10'
set autoscale y
plot "data.txt" using 1:5 ls 1 smooth bezier with lines 

Output of the gnuplot script

1
since the line is connected, i'd guess your data isn't sorted by x axis value, so it's going back and forth. if there were disconnects, i'd expect blank lines in the data file. - Jay Kominek
I thought of this, the data is sorted by time ... but I will look at it again, I am pulling it from a database, and it has never been out of order. - Xofo
if you're using a sql server, then unless you specifically tell it you want the data sorted, it can do whatever it wants. and probably will. - Jay Kominek
I am using MySQL ... I am still investigating - Xofo
Plot time against line number to check if your data is continous with "plot datafile using 0:1". If this goes up and down you know where you are with your data. - Karl

1 Answers

1
votes

You can use sort to sort your data. Consider the following data file which I have generated consistent with your time format:

2000-12-21 12:32:05 1
2001-11-21 12:32:05 2
2000-12-20 12:32:05 3
2000-12-20 12:32:04 4

Typing sort data.txt will yield the correct ordering:

2000-12-20 12:32:04 4
2000-12-20 12:32:05 3
2000-12-21 12:32:05 1
2001-11-21 12:32:05 2

You can invoke this within gnuplot by using a special input name plot "< sort data.txt" ...:

set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
plot "data.txt" using 1:3 w l

enter image description here

set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
plot "< sort data.txt" using 1:3 w l

enter image description here

You can consult the sort documentation if you need more powerful sorting with respect to your data format.