need some advice on x y plot
Grant Edwards
grante at visi.com
Tue Oct 25 12:13:36 EDT 2005
On 2005-10-25, Grant Edwards <grante at visi.com> wrote:
> It looks like it. Though I've used custom tics in the past, it
> was never for time values. Based on the help from gnuplot, I
> suspect you can get what you want without doing custom tics,
> but rather using the commands
>
> set xdata time
> set timefmt
> set format x
>
> Interestingly, using Unix timestamps creates some sort of
> resolution problems. The following ought to work but doesn't.
> It appears that there is some sort of resolution problem:
>
> ------------------------------8<------------------------------
> import Gnuplot,time,sys,math
>
> def pause():
> sys.stdout.write("Press enter to continue: ")
> sys.stdin.readline()
>
> def fgrid(start,stop,count):
> for i in xrange(count):
> yield start + ((stop-start)*i)/count
>
> start = time.time()
>
> xdata = [x for x in fgrid(0,600.0,10)] # two minutes worth
> ydata = [math.sin(x/100.0) for x in xdata]
> data = Gnuplot.Data(xdata,ydata,with='linespoints',using=(1,2))
> gp = Gnuplot.Gnuplot(debug=1)
> gp.title('Data starting at %s' % time.asctime(time.gmtime(start+xdata[0])))
>
> # x axis will use default tics (seconds since start of run)
> gp.plot(data)
> pause()
>
> # same data with x value as Unix timestamps
>
> xdata = [x+start for x in xdata]
> print xdata
> data = Gnuplot.Data(xdata,ydata,with='linespoints',using=(1,2))
>
> gp('set xdata time')
> gp('set timefmt "%s')
> gp('set format x "%r"')
> gp('set xtics 120')
> gp.plot(data)
> pause()
> ------------------------------8<------------------------------
Yup. Something in the Gnuplot module is broken. Here's the
x data I'm passing it:
[1130256529.616158, 1130256589.616158, 1130256649.616158,
1130256709.616158, 1130256769.616158, 1130256829.616158,
1130256889.616158, 1130256949.616158, 1130257009.616158,
1130257069.616158]
And here's what it's passing to gnuplot
1130256512.0 0.0
1130256640.0 0.564642488956
1130256640.0 0.93203908205
1130256768.0 0.97384762764
1130256768.0 0.675463199615
1130256768.0 0.141120001674
1130256896.0 -0.442520439625
1130256896.0 -0.871575772762
1130257024.0 -0.996164619923
1130257024.0 -0.772764503956
It appears that the Gnuplot modules has coerced my data into
single-precision -- thus throwing away most of the resolution
on the x-axis.
--
Grant Edwards grante Yow! Yow!
at
visi.com
More information about the Python-list
mailing list