From: Michael H. <hag...@jp...> - 2002-09-26 06:28:10
|
Chuck, [I have cc'ed this email to the gnuplot-py-users mailing list. Please subscribe to that list if you are interested in following Gnuplot.py developments: http://lists.sourceforge.net/lists/listinfo/gnuplot-py-users .] chuck clark <cn...@us...> writes: > Michael, > I am a decent Python programmer but just started > using Gnuplot and Gnuplot-py yesterday so please > forgive me if this is an obvious question with an > obvious answer that I've just missed. > Is there a way to plot Time/Data data in Gnuplot-py? > I've got some two dimensional data that looks like > the following: > > 12:01:30 4.63 > 12:02:30 6.74 > 12:03:30 0.0 > 12:04:30 6.32 > > I can get this to plot directly in Gnuplot but I > can't seem to create a Gnuplot.Data that can > handle the time type data. Is there something I'm > missing? If plotting this kind of data is not > possible then is there any chance Gnuplot-py will > be supporting it in the near future? I don't have any experience myself with using date-formats in gnuplot, so I wouldn't know how to support them in Gnuplot.py. The Gnuplot.py Data class stores its data internally as a Numeric array of floating point data. It has no way of storing (let alone plotting) data in another format. If gnuplot requires date data formatted as you mentioned, how would you want to store it within Gnuplot.py? As strings? Date objects of some sort? If you have a rather specific purpose in mind, you could easily write a class derived from PlotItem that prints its contents in the format that you need. If you want it to be more generally useful, you base it on the Data class but instead of using Numeric arrays of float to store its data it would use Python lists (or perhaps Numeric arrays of Python objects, though last time I checked they didn't work too well). If you decide to derive from PlotItem, then I would strongly recommend that you base your work on the latest CVS version of Gnuplot.py since the PlotItem interface has changed significantly. I haven't gotten around to making a new release but when I do it will include the new interface. In fact, I just realized that Numeric isn't really required for very much in Gnuplot.py. It might be easy to provide a non-Numeric mode, which would be interesting to me at the moment because I'm mostly using Jython in my current work and JNumeric isn't well-developed. Yours, Michael -- Michael Haggerty hag...@jp... |
From: Leonardo M. <lm...@ud...> - 2002-09-26 18:33:09
|
Hi Chuck > > Is there a way to plot Time/Data data in Gnuplot-py? > > I've got some two dimensional data that looks like > > the following: > > > > 12:01:30 4.63 > > 12:02:30 6.74 > > 12:03:30 0.0 > > 12:04:30 6.32 [...] > I don't have any experience myself with using date-formats in gnuplot, Is there a date-format data type in Python ?. I browsed the docs and couldn't find one. Or is there a class for that ?. Anyway, it seems that the more straightforwars way to go would be to write a small python function that converts a string "hh:mm:ss" into a floating point. It should be doable in a few lines of code. A little fancier would be a date class, with conversion methods. But may be that is overkill depending on what you need. Hope this helps, -- leo |
From: Michael H. <hag...@jp...> - 2002-09-26 19:01:30
|
Leonardo Milano writes: > Is there a date-format data type in Python ?. I browsed the docs > and couldn't find one. Or is there a class for that ?. There is a package called mx.DateTime or something like that with a vary capable date class, but unfortunately it is not part of standard Python. Standard Python tends to use doubles or tuples to represent date/times and the time module has lots of routines for manipulating dates/times. Michael -- Michael Haggerty hag...@jp... |
From: chuck c. <cc...@zi...> - 2002-09-27 03:03:21
|
Leo, The mxdate package which Michael speaks of is a great package indeed and handles datetime data very well and has almost any date/time functions you could think of. I think my problem lies in the fact of I'm not sure which PlotItem type from gnuplot-py I should use. I was originally trying to use Data but of course "12:01" can't be converted to a Numeric Float array. So now I'm taking a step back and wondering if I need to create my own PlotItem types of Date, Time and DateTime to do this? I thought about doing as you say about converting my hh:mm:ss string into a float but it isn't really clean because time is base 60 and not decimal and I lose a lot of readability because suddenly my x-axis is not regular times that the user would expect to see but some decimal representation of it. If I somehow try to preserve the time by making 12:01 into 1201 then I'll have funny gaps from 1260 to 1300 and on every other hour. Gnuplot itself handles Date/Time types as seen in the 3.7.1 manual. If you had the data below in a file called test.dat you could plot it in Gnuplot with the following: 12:01 4.63 12:02 6.74 12:03 0.0 12:04 6.32 gnuplot> set xdata time gnuplot> set timefmt "%H:%M" gnuplot> set format x "%H:%M" gnuplot> set xrange ["12:00":"12:05"] gnuplot> plot "/home/cclark/test.dat" using 1:2 So I guess what I was wondering was if anyone had plotted date/time data using gnuplot-py with the existing PlotItem types or if people who were more familiar with the package than I am thought I'd need to come up with a new type. Any thoughts would be greatly appreciated. cheers, chuck |
From: Michael H. <hag...@jp...> - 2002-09-27 12:25:58
|
chuck clark writes: > I think my problem lies in the fact of I'm not sure which PlotItem > type from gnuplot-py I should use. I was originally trying to use > Data but of course "12:01" can't be converted to a Numeric Float > array. So now I'm taking a step back and wondering if I need to > create my own PlotItem types of Date, Time and DateTime to do this? > [...] > gnuplot> set xdata time > gnuplot> set timefmt "%H:%M" > gnuplot> set format x "%H:%M" > gnuplot> set xrange ["12:00":"12:05"] > gnuplot> plot "/home/cclark/test.dat" using 1:2 A PlotItem object represents a whole plot including all of the associated data (if any), and the plot sub-command that has to be sent to gnuplot (e.g., '"/tmp/sxhhfy" using 1:3 with linespoints'). You can use any of the data-based PlotItems defined in the CVS version (_InlineFileItem, _FIFOFileItem, or _TempFileItem); you just have to call its constructor using the content that needs to be sent to gnuplot as one of the arguments. For example, this should work (untested): >>> content = """\ ... 12:01 4.63 ... 12:02 6.74 ... 12:03 0.0 ... 12:04 6.32 ... """ >>> plot_item = PlotItems._TempFileItem(content, with='linespoints') >>> g = Gnuplot.Gnuplot() >>> g('set xdata time') >>> g('set xdata time') >>> g('set timefmt "%H:%M"') >>> g('set format x "%H:%M"') >>> g('set xrange ["12:00":"12:05"]') >>> g.plot(plot_item) >>> The only trick is getting your data into a "content" string that gnuplot can understand. You can do that any way you want. PlotItems.Data() is now a helper function that does mainly that; you can use it as a starting point. I haven't decided whether to make the _InlineFileItem etc classes a part of the Gnuplot.py published interface, which is why their names start with '_'. I might rename them before the next Gnuplot.py release. Michael -- Michael Haggerty hag...@jp... |