By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,596 Members | 3,653 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,596 IT Pros & Developers. It's quick & easy.

need some advice on x y plot

P: n/a
Hey there,
i have tried about every graphing package for python i can get to work
on my system. gnuplot, pychart, biggles, gdchart, etc.. (cant get
matplot to work)
so far, they all are working ok. I need to make an x y chart for some
data that comes in from sensors at different times durring the day. i
need it to show the value in the y and the time in the x . no problem
so far. But what i cannot get to happen is to scale x (time of the
plot) with respect to time. in other words, i get a chart with the
times evenly spaced out along the x axis, with their respective values.
i need the chart to show gaps when there are gaps in the data. i need
it to be able to scale by time. if i have 3 values that come in within
a few minutes, i need them to be displayed close together, as compared
to another value that may come in, say, an hour later. Does this make
sence ?
one of you guys know a charting app that will do this ? or is there
some other way i could do it?

looking for suggestions,
sk

Oct 20 '05 #1
Share this Question
Share on Google+
30 Replies


P: n/a
On 2005-10-20, ne*****@xit.net <ne*****@xit.net> wrote:
[...] I need to make an x y chart for some data that comes in
from sensors at different times durring the day. i need it to
show the value in the y and the time in the x . no problem so
far. But what i cannot get to happen is to scale x (time of
the plot) with respect to time.


Gnuplot does that just fine. Just give it two columns of data, the
first being the x value (time) and the second being the y value.

All of the other plotting packages handle this as well.

--
Grant Edwards grante Yow! I hope I
at bought the right
visi.com relish... zzzzzzzzz...
Oct 20 '05 #2

P: n/a
how ?
i have tried to use unix timestamps, and i have also tried with
DateTime objects
do i need to use a scale that isn't linear (default in most) ?
how do i putt this off ?

thanks btw.
sk

Oct 20 '05 #3

P: n/a
I would try to live with time scale being fixed and insert
None (or whatever value is used by charting package) for
times where observations were not taken. This will mean that
you have to preprocess your data by determining a time step
step value that will fit your data. If you get 3 observations
each 10 minutes apart then one an hour later, you will need to
insert 5 empty observations in the list before the last
observation.

Example:

1:00 <value1>
1:10 <value2>
1:20 <value3>
2:20 <value4>

1:00 <value1>
1:10 <value2>
1:20 <value3>
1:30 <empty value>
1:40 <empty value>
1:50 <empty value>
2:00 <empty value>
2:10 <empty value>
2:20 <value4>

Maybe this will be of some help and I'm sure there are other ways.

-Larry

ne*****@xit.net wrote:
Hey there,
i have tried about every graphing package for python i can get to work
on my system. gnuplot, pychart, biggles, gdchart, etc.. (cant get
matplot to work)
so far, they all are working ok. I need to make an x y chart for some
data that comes in from sensors at different times durring the day. i
need it to show the value in the y and the time in the x . no problem
so far. But what i cannot get to happen is to scale x (time of the
plot) with respect to time. in other words, i get a chart with the
times evenly spaced out along the x axis, with their respective values.
i need the chart to show gaps when there are gaps in the data. i need
it to be able to scale by time. if i have 3 values that come in within
a few minutes, i need them to be displayed close together, as compared
to another value that may come in, say, an hour later. Does this make
sence ?
one of you guys know a charting app that will do this ? or is there
some other way i could do it?

looking for suggestions,
sk

Oct 20 '05 #4

P: n/a
i have thought about doing this, just a little different. i was going
to list the value pairs.
take the start time and end time and plot 100 empty plots between them.
add the value pairs, sort by time, and then draw it. The only thing is
it get kinda complicated when the times change a lot. they could span
an hour, a month, anything in between.

i like your idea, i will check various packages for how to plot 'none'

thanks
sk.

Oct 20 '05 #5

P: n/a
On 2005-10-20, ne*****@xit.net <ne*****@xit.net> wrote:
i have tried to use unix timestamps,
That has always worked for me. What happened?
and i have also tried with DateTime objects
Never tried that.
do i need to use a scale that isn't linear (default in most) ?
No.
how do i putt this off ?


Huh?

Gnuplot by default does exactly what you seem to want if you
just pass it x,y values.

--
Grant Edwards grante Yow! I always liked FLAG
at DAY!!
visi.com
Oct 20 '05 #6

P: n/a
On 2005-10-20, Larry Bates <la*********@websafe.com> wrote:
I would try to live with time scale being fixed
I don't understand what you mean by "the time scale being
fixed". It's not. If you just pass the time,value pairs to
gnuplot, it does exactly what it should.
and insert
None (or whatever value is used by charting package) for
times where observations were not taken. This will mean that
you have to preprocess your data by determining a time step
step value that will fit your data. If you get 3 observations
each 10 minutes apart then one an hour later, you will need to
insert 5 empty observations in the list before the last
observation.

Example:

1:00 <value1>
1:10 <value2>
1:20 <value3>
2:20 <value4>

1:00 <value1>
1:10 <value2>
1:20 <value3>
1:30 <empty value>
1:40 <empty value>
1:50 <empty value>
2:00 <empty value>
2:10 <empty value>
2:20 <value4>


That's completely unnecessary. Just pass a set of time,value
pairs and they'll get plotted as desired.

--
Grant Edwards grante Yow! As a FAD follower,
at my BEVERAGE choices are
visi.com rich and fulfilling!
Oct 20 '05 #7

P: n/a
On 2005-10-20, Grant Edwards <gr****@visi.com> wrote:
and insert None (or whatever value is used by charting
package) for times where observations were not taken. This
will mean that you have to preprocess your data by determining
a time step step value that will fit your data. If you get 3
observations each 10 minutes apart then one an hour later, you
will need to insert 5 empty observations in the list before
the last observation.
[...]
That's completely unnecessary. Just pass a set of time,value
pairs and they'll get plotted as desired.


For example, here's how gnuplot plots the data

2 12
3 10
4 9
101 8
102 6
103 9

20 ++----------+-----------+-----------+----------+-----------+----------++
+ + + + + "foo.dat" A +
| |
| |
| |
15 ++ ++
| |
| |
|A |
| |
10 ++A ++
| A A |
| A |
| |
| A |
5 ++ ++
| |
| |
| |
+ + + + + + +
0 ++----------+-----------+-----------+----------+-----------+----------++
0 20 40 60 80 100 120
Isn't that what you're asking for?

--
Grant Edwards grante Yow! ... I have read the
at INSTRUCTIONS...
visi.com
Oct 20 '05 #8

P: n/a
ne*****@xit.net wrote:
how ?
i have tried to use unix timestamps, and i have also tried with
DateTime objects
do i need to use a scale that isn't linear (default in most) ?
how do i putt this off ?


Here is some code that works for me. It plots multiple datasets against time. The input data looks like this:
2005-04-04 16:00:00 141.154.195.129 - W3SVC1 SP6018ASP2 208.254.37.191 443 GET /rkadqsr/newskills/newskills.cfm selectedTab=1 200 0 53440 599 1594 HTTP/1.1 adqsr.skillport.com Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) CookiesEnabled=1;+ASPSESSIONIDACTSSRAT=MCNLNLGADPO FGFKAHJHLDDKG;+CFID=785030;+CFTOKEN=27203160 https://adqsr.skillport.com/rkadqsr/login/login.cfm
2005-04-04 16:00:00 208.254.38.216 - W3SVC1 SP6018ASP2 208.254.37.191 443 POST /_rkadqsrBackend_od_cgi/aiccisapi.dll - 200 0 372 274 4547 HTTP/1.0 adqsr.skillport.com aiccisapi - -
2005-04-04 16:00:00 208.254.38.240 - W3SVC1 SP6018ASP2 208.254.37.191 443 POST /_rkadqsrBackend_od_cgi/aiccisapi.dll - 200 0 372 3019 250 HTTP/1.0 adqsr.skillport.com aiccisapi - -

import datetime, time
import Gnuplot

dataPath = 'ex05040416.log'

datasets = {}
startTime = None

f = open(dataPath)

for line in f:
try:
dat, tim, c_ip, cs_username, s_sitename, s_computername, s_ip, s_port, \
cs_method, cs_uri_stem, cs_uri_query, sc_status, sc_win32_status, sc_bytes, \
cs_bytes, time_taken, cs_version, cs_host, cs_User_Agent, cs_Cookie, cs_Referer = line.split()
except ValueError:
print "Can't parse", line
continue

tim = time.mktime(time.strptime(dat+' '+tim, "%Y-%m-%d %H:%M:%S"))
delay = int(time_taken)

if startTime is None:
startTime = tim

tim -= startTime

# print tim, delay
datasets.setdefault(sc_status, []).append([tim, delay])

g = Gnuplot.Gnuplot(debug=1)

plotter = g.plot
for key, values in datasets.items():
plotter(values)
plotter = g.replot

raw_input('Please press return to continue...\n')
Oct 20 '05 #9

P: n/a
ok, yeah, thats exactly what i am looking for. i will give it a go.
thanks a whole lot.

putt this off is a typo, pull this off is what i was meaning to type.

this is cool.

Oct 20 '05 #10

P: n/a
ok, i tried something similar to what you posted.
a little simpler though.
i am running a query on a database and making a list of time, value
pairs
kinda like this
plot_points = ([time, value], [time, value], [time, value])
gnuplot complains that it needs a float for one of the values.
i can plot just the value, and it shows up ( no x value found)

how should i proceed?

Oct 21 '05 #11

P: n/a
ne*****@xit.net wrote:
i am running a query on a database and making a list of time, value
pairs
kinda like this
plot_points = ([time, value], [time, value], [time, value])
gnuplot complains that it needs a float for one of the values.
i can plot just the value, and it shows up ( no x value found)

how should i proceed?


Convert one of the values to a float? What are your time and value numbers?

Kent
Oct 21 '05 #12

P: n/a
the time is DateTime.DateTime object from a mySQLdb query.
the value is a number anywhere between 0 and 15.
the datetime is formatted like 2005-10-20 08:40:34

i could strip it and make a timestamp out of it. but reading the
number of seconds since january of 1970 doesn't make a neat chart.

any suggestions?

oh, and can you output from Gnuplot to a png or jpeg or something like
that.
the Gnuplot documentation says that it can make a bitmap png but i dont
know how to do that with the python wrapper. the docs for this are a
little cryptic.
still a newbie here. if you know a good tutorial on this, i would
really appreciate the link.

thanks for your time, and brain

Oct 21 '05 #13

P: n/a
ne*****@xit.net wrote:
the time is DateTime.DateTime object from a mySQLdb query.
the value is a number anywhere between 0 and 15.
the datetime is formatted like 2005-10-20 08:40:34

i could strip it and make a timestamp out of it. but reading the
number of seconds since january of 1970 doesn't make a neat chart.

any suggestions?


Python is capable of integer arithmetic, eg.
2000 - 500

1500

--
William Park <op**********@yahoo.ca>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
http://freshmeat.net/projects/bashdiff/
Oct 21 '05 #14

P: n/a
On 2005-10-21, ne*****@xit.net <ne*****@xit.net> wrote:
the time is DateTime.DateTime object from a mySQLdb query. the
value is a number anywhere between 0 and 15. the datetime is
formatted like 2005-10-20 08:40:34

i could strip it and make a timestamp out of it. but reading
the number of seconds since january of 1970 doesn't make a
neat chart.
Pass the data values as floating point numbers (I typically use
seconds since the test run started). If you the x tics to be
something else, then change them. It's pretty simple to label
the x-axis using normal date/time notation.
any suggestions?

oh, and can you output from Gnuplot to a png or jpeg or
something like that.
Is that a question? If so, the answer is yes.
the Gnuplot documentation says that it can make a bitmap png
but i dont know how to do that with the python wrapper. the
docs for this are a little cryptic. still a newbie here. if
you know a good tutorial on this, i would really appreciate
the link.


Once you start doing "odd" stuff (e.g. custom labels for the x-axis,
output other than X11 or postscript), it's usually simplest to
just send normal gnuplot commands.

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

gp = Gnuplot.Gnuplot()
gp.title('Data starting at %s' % time.ctime(start+xdata[0]))

# x axis will use default tics (seconds since start of run)
gp.plot(data)
pause()

# now let's change x tics to time of day in HH:MM:SS with
# ticmarks at 120 second intervals

ti = 120.0
startTic = int((start+xdata[0])//ti * ti)
endTic = int((start+xdata[-1])//ti * ti)
ti = int(ti)

ticx = range(startTic,endTic+ti,ti)
tics = [(x, time.strftime('%H:%M:%S',time.localtime(x))) for x in ticx]
ticstrings = ['"%s" %f' % (t[1],t[0]-start) for t in tics]

gp('set xtics (%s)' % ','.join(ticstrings))
gp.plot(data)
pause()

outfile = 'foo.png'
gp('set term png')
gp('set out "%s"' % outfile)
gp.plot(data)
------------------------------8<------------------------------

--
Grant Edwards grante Yow! ... The waitress's
at UNIFORM sheds TARTAR SAUCE
visi.com like an 8" by 10" GLOSSY...
Oct 21 '05 #15

P: n/a
ok, i have a display, and its a work in progress.

lemme get this straight. you used

gp('set term png')

is this an example of sending normal gnuplot commands?
if so, are all of the gnuplot commands available ?
thanks so much this is helping me out a lot here

Oct 21 '05 #16

P: n/a
On 2005-10-21, ne*****@xit.net <ne*****@xit.net> wrote:
gp('set term png')

is this an example of sending normal gnuplot commands?
Yes.
if so, are all of the gnuplot commands available ?


Yes.

--
Grant Edwards grante Yow! Do you like "TENDER
at VITTLES"?
visi.com
Oct 21 '05 #17

P: n/a
this is great, because the docs on gnuplots website are a bit easier
for me to grasp.
thanks so much for your time on this one. you really have helped me a
lot.
i will not get a change to work on this till monday. so i may have more
questions then. This is sure a point in the right direction.

thanks much.
shawn

Oct 21 '05 #18

P: n/a
ok, i am stuck a bit here with this line

gp('set xtics (%s)' % ','.join(ticstrings))

the error code says that it is looking for a closing parenthesis.
that and i am kinda new enough not to really get what %s is all about.
i know it formats a string.

can you simply pass a list to 'set xtics' ?

i mean, i got this from the gnuplot site

Syntax:

set xtics {axis | border} {{no}mirror} {{no}rotate {by <ang>}}
{offset <offset> | nooffset}
{ autofreq
| <incr>
| <start>, <incr> {,<end>}
| ({"<label>"} <pos> {<level>} {,{"<label>"}...) }
{ font "name{,<size>}" }
{ textcolor <colorspec> }
unset xtics
show xtics

but it does not look like all the options are necessary from the docs,
i guess i am asking, if i just wanted to pass a list of say, 14 tics to
the x axis as a list, what of the above is necessary ?

i built the list by taking time stamps in seconds (the same as being
plotted for x) took the end time minus the start time and divided by
12, incremented each by this amount until i had 12 plots (plus of
course the first and last).
these are all stored in plot_times[]..

any tips ?

sorry if this all sounds a bit scrambled. i just got the hang of
changing from a datetime.datetime to time in epoch seconds. ( these
little triumphs keep me going )

thanks for your help. the graph i built looks great, and looks right
referenced with time. just neeed to print the x a little easier to
read.

thanks again,

shawn

Oct 24 '05 #19

P: n/a
On 24 Oct 2005 15:58:25 -0700, ne*****@xit.net declaimed the following
in comp.lang.python:
ok, i am stuck a bit here with this line

gp('set xtics (%s)' % ','.join(ticstrings))

the error code says that it is looking for a closing parenthesis.
that and i am kinda new enough not to really get what %s is all about.
i know it formats a string.

can you simply pass a list to 'set xtics' ?

i mean, i got this from the gnuplot site

Syntax:

set xtics {axis | border} {{no}mirror} {{no}rotate {by <ang>}}
{offset <offset> | nooffset}
{ autofreq
| <incr>
| <start>, <incr> {,<end>}
| ({"<label>"} <pos> {<level>} {,{"<label>"}...) }
{ font "name{,<size>}" }
{ textcolor <colorspec> }
unset xtics
show xtics
The only option I see that uses parens and commas is the fourth
option in the block starting { autofreq.

The problem is: What does ticstrings contain?
-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Oct 25 '05 #20

P: n/a
well, for what i tried, ticstrings just contained a list of times
formatted like
[10-21 09:15, 10-21 09:44, 10-21 09:59, and so on.....]
i did write mine a little different than the example that Grant gave me
because its a little
different application of time.

i think i am having trouble knowing exactly what the set xtics line is
looking for.
thanks

Oct 25 '05 #21

P: n/a
On 2005-10-24, ne*****@xit.net <ne*****@xit.net> wrote:
ok, i am stuck a bit here with this line

gp('set xtics (%s)' % ','.join(ticstrings))

the error code says that it is looking for a closing parenthesis.
Well, what is the value of ticstrings?

Try passing the parameter debug=1 to Guplot.Gnuplot():

gp = Gnuplot.Gnuplot(debug=1)

Then it will print out all of the gnuplot commands to stdout.
that and i am kinda new enough not to really get what %s is
all about. i know it formats a string.
http://www.google.com/search?hl=en&q...ing+formatting

Follow the first hit.
can you simply pass a list to 'set xtics' ?
That depends. What do you mean by "a list", and what do you
mean "pass it to 'set xtics'"?
i mean, i got this from the gnuplot site

Syntax:

set xtics {axis | border} {{no}mirror} {{no}rotate {by <ang>}}
{offset <offset> | nooffset}
{ autofreq
| <incr>
| <start>, <incr> {,<end>}
| ({"<label>"} <pos> {<level>} {,{"<label>"}...) }
{ font "name{,<size>}" }
{ textcolor <colorspec> }
unset xtics
show xtics

but it does not look like all the options are necessary from
the docs, i guess i am asking, if i just wanted to pass a list
of say, 14 tics to the x axis as a list, what of the above is
necessary ?
Well, you could start up gnuplot at the command line and try a
few "set xtics" commands. That's how I figur gnuplot commands
out. The format for the set xtics command that I was using in
my demo was

set xtics ("label" pos, "label" pos, "label" pos)
i built the list by taking time stamps in seconds (the same as
being plotted for x) took the end time minus the start time
and divided by 12, incremented each by this amount until i had
12 plots (plus of course the first and last). these are all
stored in plot_times[]..


We can't read your mind. Unless you show us actual code, we
can't help. Show us a small example program with Gnuplot's
debug feature enabled that doesn't do what you want it to.

Tell us what it is you wanted the program to do and post the
output from that program. Do _not_ attempt to re-type the
output from the program. Either redirect it to a file or
cut/paste it.

--
Grant Edwards grante Yow! PUNK ROCK!! DISCO
at DUCK!! BIRTH CONTROL!!
visi.com
Oct 25 '05 #22

P: n/a
On 2005-10-25, ne*****@xit.net <ne*****@xit.net> wrote:
well, for what i tried, ticstrings just contained a list of times
formatted like
[10-21 09:15, 10-21 09:44, 10-21 09:59, and so on.....]
OK. What did ticstrings contain in the demo I wrote for you?

[When somebody who is trying to help you asks what the value of
an object was in your program just paste the output from
repr(obj). If you try to describe the contents in English, I
guarantee it won't be sufficient.]
i did write mine a little different than the example that
Grant gave me
Well, that's your problem. Look at the ticstrings value that
worked, and look at the ticstrings value that didn't work.

What is the difference between the two?
because its a little different application of time.

i think i am having trouble knowing exactly what the set xtics
line is looking for.


--
Grant Edwards grante Yow! .. someone in DAYTON,
at Ohio is selling USED
visi.com CARPETS to a SERBO-CROATIAN
Oct 25 '05 #23

P: n/a

<ne*****@xit.net> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...

If the x-axis is time, gnuplot will plot it correctly but it will connect
*all* the datapoints and scale the x-axis so that everything will fit on the
graph. Is it the autoscaling or conneting that what you think is wrong?

Getting a fixed-size x-axis is a configuration option. I think one simply
passes a range to the axis one wants to scale. I cannot remember exactly,
how though.
one of you guys know a charting app that will do this ? or is there
some other way i could do it?


RRDTool is excellent at storing & plotting time series data. It will not
"connect" missing data points but has the limitation that the sample rate
must be known when creating the database and generally adhered to. Missed
samples are NAN's.

You have to "tell" gnuplot what to plot and what not to plot. I think you
can add more than one data series to the same plot, providing the "gap"
where data is unavaliable. Else you have to "pad" it with zeros or some
other appropriate null value.
Oct 25 '05 #24

P: n/a
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

Oct 25 '05 #25

P: n/a
On 2005-10-25, ne*****@xit.net <ne*****@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
Oct 25 '05 #26

P: n/a
On 2005-10-25, Grant Edwards <gr****@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
Oct 25 '05 #27

P: n/a
On 2005-10-25, Grant Edwards <gr****@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
Oct 25 '05 #28

P: n/a
On 25 Oct 2005 08:18:39 -0700, ne*****@xit.net declaimed the following
in comp.lang.python:


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.
pos (position) is the one part of that syntax you CANNOT leave out.
The label is optional. Sounds like you are trying to supply labels
without telling it where on the line to put them.
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)))
I think you need to interleave the string label with the RAW numbers
(as the raw numbers are what the plotting package should be using to
position data -- hopefully you don't have to also zero-normalize them
and the actual data). Something like

tics.append('"%s" %s' % (time.strftime(...), x))
# might need time.localtime(x) for that last term.

Each list item should then be a string consisting of a double-quoted
label followed by a numeric "position" value.
-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Oct 25 '05 #29

P: n/a
tics.append('"%s" %s' % (time.strftime(...), x))
# might need time.localtime(x) for that last term.

ok, tried this and it worked.
but the first plot is at the last plot of data
back to that math mistake i mentioned earlier.
so, thanks much, i will be back when i mess around with it some more
and
see if i can get it right.
thanks very very much guys,

i know i sound frustrated and ignorant, but i am having a lot of fun
with this

Oct 25 '05 #30

P: n/a
WE DID IT !
little more tinkering and correcting this
diff = start_time - end_time (vrs the other way around)

and its working.

so many thanks gents, a lot !

Oct 25 '05 #31

This discussion thread is closed

Replies have been disabled for this discussion.