Reputation: 1278
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
Upvotes: 0
Views: 199
Reputation: 7627
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
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
plot "< sort data.txt" using 1:3 w l
You can consult the sort
documentation if you need more powerful sorting with respect to your data format.
Upvotes: 1