need some advice on x y plot

Grant Edwards grante at visi.com
Tue Oct 25 11:52:00 EDT 2005


On 2005-10-25, nephish at xit.net <nephish at xit.net> wrote:

> Ok, first off, thanks for all the help guys,
>
> this part "set xtics ("label" pos, "label" pos, "label" pos)"
> is mainly what i was confused about. the 'pos' part. i think
> that the way i am writing this leaves this out. in fact, i am
> pretty sure.

Yup, it looks like it.

> here is the code i am trying out.

[Another hint: when posting code, don't wrap it.  It won't run
as it was posted, and people aren't generally going to be willing to go
through and un-wrap the lines in order to try it.]

> gnuplot> set title "testing"
> gnuplot> set term png
> gnuplot> set out "/home/piv/PivData/tmp/images/graph.png"
> gnuplot> set xtics (['10/18 09:54', '10/17 22:42', '10/17 11:30',
> '10/17 00:18', '10/16 13:06', '10/16 01:54', '10/15 14:42', '10/15
> 03:30', '10/14 16:18', '10/14 05:06', '10/13 17:54', '10/13 06:42',
> '10/12 19:30', '10/12 08:18', '10/25 09:54'])

OK, You need to get rid of the sqare brackets, and you need an
x-position value after each of the strings.

> i noticed in the docs for gnuplot, that it can do date/time
> and by default uses seconds since 2000. and then you can pass
> the format that you want to show it in. would this give the
> same kind of result that i am looking for ?

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<------------------------------

   
-- 
Grant Edwards                   grante             Yow!  LOOK!!! I'm WALKING
                                  at               in my SLEEP again!!
                               visi.com            



More information about the Python-list mailing list