need some advice on x y plot

nephish at xit.net nephish at xit.net
Tue Oct 25 11:18:39 EDT 2005


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.

here is the code i am trying out.

def draw_chart(self, StartTime, EndTime):
    	# make start time and end time markers in  seconds
    	start_tic = time.mktime(time.strptime(StartTime, '%Y-%m-%d
%H:%M:%S'))
    	end_tic = time.mktime(time.strptime(EndTime, '%Y-%m-%d %H:%M:%S'))
    	# get the difference in seconds between start and end times
    	diff_time = start_tic - end_tic
    	# get tick marks with respect to time
    	tic_increment = diff_time / 15
    	#build an array of ticmarks
    	tics_raw = []
    	tics_raw.append(start_tic)
    	tic_adder = start_tic
    	for x in range(13):
    		tic_adder = tic_adder + tic_increment
    		tics_raw.append(tic_adder)

    	#add the last time to the tics array
    	tics_raw.append(end_tic)

    	# change all the tic increments to reader understandable values
    	tics = []
    	for x in tics_raw:
    		tics.append(time.strftime('%m/%d %H:%M', time.localtime(x)))
    		print 'tic '+(time.strftime('%m/%d %H:%M', time.localtime(x)))

        # get the plot points date / value
    	Sensor =  self.GraphSensorEntry.get_text()
        db = MySQLdb.connect(host="localhost", user="piv",
passwd="crayon99", db="DDS")
        cursor=db.cursor()
        cursor.execute("SELECT `Raw`, `DateTime` FROM `Process` WHERE
`Sensor_ID` = '"+Sensor+"' \
        AND `DateTime` > '"+StartTime+"' AND `DateTime` < '"+EndTime+"'
ORDER BY `DateTime` ")
        results = cursor.fetchall()
        plot_x = []
        plot_y = []
        for row in results:
        	Value = row[0]
        	#convert datetime.datetime object to epoch (seconds) object
        	Time = time.mktime(row[1].timetuple())
        	print time.strftime('%m/%d %H:%M:%S', time.localtime(Time))

        	plot_x.append(float(Time))
        	plot_y.append(float(Value))
        g = Gnuplot.Gnuplot(debug=1)
        g.title('testing')
        data = Gnuplot.Data(plot_x,plot_y)
        outfile = '/home/piv/PivData/tmp/images/graph.png'
        g('set term png')
        g('set out "%s"' % outfile)
        g('set xtics (%s)' % (tics))
        g.plot(data)

self.GraphImage.set_from_file('/home/piv/PivData/tmp/images/graph.png')



and this is the terminal output i get

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'])
gnuplot> plot '/tmp/tmpn2URt2' notitle

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'])
                    ^
         line 0: invalid expression


it is drawing the graph though, and it looks right compared with the
data

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 ?


my math in how i am doing this is kinda off too, i think.
for the stuff i am doing on our website, i use php with jpgraph, it
does things a little
different. 

thanks for everything
shawn




More information about the Python-list mailing list