need some advice on x y plot

Grant Edwards grante at visi.com
Tue Oct 25 12:37:55 EDT 2005


On 2005-10-25, Grant Edwards <grante at visi.com> wrote:

> It appears that the Gnuplot modules has coerced my data into
> single-precision -- thus throwing away most of the resolution
> on the x-axis.

Passing Gnuplot.Data a Numeric array object is a good
work-around.  Otherwise, Gnuplot.Data will convert it into a
float (single precision) arry.

Here's a revised demo that works better:

------------------------------8<------------------------------
import Gnuplot,time,sys,math
import Numeric

Gnuplot.GnuplotOpts.prefer_fifo_data = 0

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]
a = Numeric.array(zip(xdata,ydata))

data = Gnuplot.Data(a,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<------------------------------

-- 
Grant Edwards                   grante             Yow!  The Korean War must
                                  at               have been fun.
                               visi.com            



More information about the Python-list mailing list