Re: matplotlib: Plotting a graph against time

2008-07-20 Thread arsyed
On Jul 19, 3:09 pm, Durand <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm trying to plot a simple graph against date or time using matplotlib. I've 
> read about date_plot but I'm not really sure how to use it. At the moment, I 
> have some data arranged into lists, where list1 contains x values (time) and 
> list2 contains y values just like is needed for the normal plot function. The 
> time values are simply the output of datetime.date.today(), etc which I don't 
> mind changing the format of.
>
> My question is, how do I plot the graph with list1 on the x axis and list2 on 
> the y axis. Using plot and unixtime I get a very ugly scale as is to be 
> expected so I want to know how to use the date_plot function efficiently. At 
> the moment, I'm only concerned about the actual plotting but help with 
> Locater Ticks (Months and Years) is also very appreciated.
>
> Thanks a lot!


I'm not sure if this is what you're looking for, but here's a quick
sample that uses plot_date to plot some random values.

import pylab, random
from datetime import datetime, timedelta

today = datetime.now()

dates = [today + timedelta(days=i) for i in range(10)]
values = [random.randint(1, 20) for i in range(10)]
pylab.plot_date(pylab.date2num(dates), values, linestyle='-')


--
http://mail.python.org/mailman/listinfo/python-list


Re: matplotlib: Plotting a graph against time

2008-07-20 Thread arsyed
On Sun, Jul 20, 2008 at 9:57 AM, Durand <[EMAIL PROTECTED]> wrote:

> Oooh, this is almost what I want but I'm not really sure how I'd
> incorporate this into real dates...
> If I have a list of dates like ['2008-07-18 14:36:53.494013',
> '2008-07-20 14:37:01.508990', '2008-07-28 14:49:26.183256'], how would
> I convert it to a format that pylab can understand? When I tried
> type(datetime.now()) it gave me datetime.datetime whereas the objects
> in this list are strings...Am I doing something wrong here?
> --
> http://mail.python.org/mailman/listinfo/python-list
>


To convert strings to date, you can use datetime.strptime but it doesn't
seem to handle fractional seconds.  I usually opt for the dateutil module
[1]:

import dateutil, pylab

datestrings = ['2008-07-18 14:36:53.494013','2008-07-20 14:37:01.508990',
'2008-07-28 14:49:26.183256']
dates = [dateutil.parser.parse(s) for s in datestrings]
pylab.plot_date(pylab.date2num(dates), values, linestyle='-')

where values is the list of corresponding y-values.


[1] http://labix.org/python-dateutil
--
http://mail.python.org/mailman/listinfo/python-list

Re: examples of pipe usage?

2008-07-20 Thread arsyed
On Sun, Jul 20, 2008 at 5:27 PM, Sean McIlroy <[EMAIL PROTECTED]>
wrote:

> hola
>
> i'd like to control another interpreter from idle. i don't have any
> experience using unix but i think a "pipe" is what i need. am i right
> about this? can anybody point me to a simple example of using a pipe
> (if that's the right thing) for this kind of task? thanks if you can
> help.
>
>
Take a look at the URL below which has a bunch of examples of using the
subprocess module to interact with other processes.

http://blog.doughellmann.com/2007/07/pymotw-subprocess.html
--
http://mail.python.org/mailman/listinfo/python-list

Re: calling source command within python

2008-07-21 Thread arsyed
On Mon, Jul 21, 2008 at 1:59 PM, mk <[EMAIL PROTECTED]> wrote:

> Jie wrote:
>
>> Hi all,
>>
>> i'm having trouble executing os.system('source .bashrc') command
>> within python, it always says that source not found and stuff. Any
>> clue?
>>
>
> It _might_ be that the shell it fires up is /bin/sh and this in turn is not
> bash.
>
> Anyway, it's better to use subprocess / Popen for this sort of operation.
>
>
>
"source" is a bash built-in command and not an executable file. That's why
you need to do something like execute "/bin/bash .bashrc".
--
http://mail.python.org/mailman/listinfo/python-list

Re: The Importance of Terminology's Quality

2008-07-22 Thread arsyed
On Tue, Jul 22, 2008 at 5:21 AM, Martin Gregorie
<[EMAIL PROTECTED]> wrote:
> On Tue, 24 Jun 2008 18:42:15 -0400, John W Kennedy wrote:
>
>> David Combs wrote:
>>> passing
>>> *unnamed* functions as args (could Algol 60 also do something like that,
>>> via something it maybe termed a "thunk")
>>
>> No, the "thunks" were necessary at the machine-language level to
>> /implement/ ALGOL 60, but they could not be expressed /in/ ALGOL.
>>
> Are you sure about that?
>
> The first time I ran across the term "thunking" was when Windows 3
> introduced the Win32S shim and hence the need to switch addressing between
> 16 bit and 32 bit modes across call interfaces. That was called "thunking"
> by Microsoft and even they would surely admit it was a kludge.
>
> I used Algol 60 on an Elliott 503 and the ICL 1900 series back when it was
> a current language. The term "thunking" did not appear in either compiler
> manual nor in any Algol 60 language definition I've seen. A60 could pass
> values by name or value and procedures by name. That was it. Call by name
> is what is now referred to as reference passing.
>


On Tue, Jul 22, 2008 at 5:21 AM, Martin Gregorie
<[EMAIL PROTECTED]> wrote:
> On Tue, 24 Jun 2008 18:42:15 -0400, John W Kennedy wrote:
>
>> David Combs wrote:
>>> passing
>>> *unnamed* functions as args (could Algol 60 also do something like that,
>>> via something it maybe termed a "thunk")
>>
>> No, the "thunks" were necessary at the machine-language level to
>> /implement/ ALGOL 60, but they could not be expressed /in/ ALGOL.
>>
> Are you sure about that?
>
> The first time I ran across the term "thunking" was when Windows 3
> introduced the Win32S shim and hence the need to switch addressing between
> 16 bit and 32 bit modes across call interfaces. That was called "thunking"
> by Microsoft and even they would surely admit it was a kludge.
>
> I used Algol 60 on an Elliott 503 and the ICL 1900 series back when it was
> a current language. The term "thunking" did not appear in either compiler
> manual nor in any Algol 60 language definition I've seen. A60 could pass
> values by name or value and procedures by name. That was it. Call by name
> is what is now referred to as reference passing.
>

Thunk has more than one meaning. The ALGOL 60 usage predates Windows
obviously.  Also, call-by-name is distinct from call-by-reference.
See:

http://en.wikipedia.org/wiki/Evaluation_strategy

And, for fun with call-by-name:

http://en.wikipedia.org/wiki/Jensen%27s_Device
http://en.wikipedia.org/wiki/Man_or_boy_test
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyOpenGL Tutorial?

2008-07-23 Thread arsyed
On Wed, Jul 23, 2008 at 4:07 PM, Clay Hobbs <[EMAIL PROTECTED]> wrote:
> I need a tutorial for PyOpenGL (specifically, to be used with wxPython).
> I searched with Google and didn't find one.  Does anybody know where one
> is?
>
> -- Ratfink
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Showmedo recently put up a tutorial screencast of using wx, opengl,
python to build a molecular viewer:

http://showmedo.com/videos/series?name=vXJsRwlBX

Also, see:

http://www.siafoo.net/browse?keyword_id=245
--
http://mail.python.org/mailman/listinfo/python-list


Re: Autocompletion and Interactive Tables in a Python IDE

2008-07-24 Thread arsyed
On Wed, Jul 23, 2008 at 5:28 PM, Anthony <[EMAIL PROTECTED]> wrote:
> Hi, I'm a FoxPro programmer, but I want to learn python before it's
> too late.  I do a lot of statistical programming, so I import SPSS
> into python.  In my opinion, the best features of Visual FoxPro 9.0
> were:
> a) Intellisense (tells you what classes/methods are available and what
> variables go into a function)
> b) Code Completion (guesses your code after four letters)
> c) Data-Orientation; multiple data sessions can be open, data can be
> viewed easily
>
> Python's IDLE has only half of the first of these features.  I did a
> lot of searching and found the PyDev extensions for Eclipse's Python
> IDE, and found that they've got Intellisense.  I'm still missing b and
> c, and am getting extremely frustrated programming so slowly..
>
> So two questions:
> Is there any package, gui, IDE, anything that will do FoxPro-style
> code completion?  If it works in Eclipse, even better..
> I can't find a good screenshot, but here's a better description:
> You type "BROW" and it pops up a window that says "BROWSE" ..at this
> point if you hit enter it completes the word..
>
> and
>
> How can I view open SPSS data in one of the Python GUIs?  Again,
> Eclipse would be the preference.
> Here's an example of how I'd like to browse the data:
> http://www.vfpconversion.com/ArticleImage.aspx?QuickID=0209071&Image=vfptoolkit_figure02.tif
> I don't want to have to switch back and forth between Python and SPSS
> while I'm programming; I just want to stay in one of them..
>
> What can I do?  I feel extremely inefficient when I don't have these
> three features..
>

I don't know of any python IDE that provides the data orientation
feature, but there may be an Eclipse plugin for that sort of thing.

Otherwise, if you're on windows, check out PyScripter, which is free:

http://mmm-experts.com/Products.aspx?ProductId=4

and WingIDE which is quite nice and cross-platform (not free, though):

http://www.wingware.com/

I use Vim, which is worth learning IMHO, but somewhat difficult to get
started with especially if you're coming from FoxPro.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Autocompletion and Interactive Tables in a Python IDE

2008-07-24 Thread arsyed
On Wed, Jul 23, 2008 at 5:28 PM, Anthony <[EMAIL PROTECTED]> wrote:
> Hi, I'm a FoxPro programmer, but I want to learn python before it's
> too late.  I do a lot of statistical programming, so I import SPSS
> into python.  In my opinion, the best features of Visual FoxPro 9.0
> were:
> a) Intellisense (tells you what classes/methods are available and what
> variables go into a function)
> b) Code Completion (guesses your code after four letters)
> c) Data-Orientation; multiple data sessions can be open, data can be
> viewed easily
>
> Python's IDLE has only half of the first of these features.  I did a
> lot of searching and found the PyDev extensions for Eclipse's Python
> IDE, and found that they've got Intellisense.  I'm still missing b and
> c, and am getting extremely frustrated programming so slowly..
>
> So two questions:
> Is there any package, gui, IDE, anything that will do FoxPro-style
> code completion?  If it works in Eclipse, even better..
> I can't find a good screenshot, but here's a better description:
> You type "BROW" and it pops up a window that says "BROWSE" ..at this
> point if you hit enter it completes the word..
>
> and
>
> How can I view open SPSS data in one of the Python GUIs?  Again,
> Eclipse would be the preference.
> Here's an example of how I'd like to browse the data:
> http://www.vfpconversion.com/ArticleImage.aspx?QuickID=0209071&Image=vfptoolkit_figure02.tif
> I don't want to have to switch back and forth between Python and SPSS
> while I'm programming; I just want to stay in one of them..
>
> What can I do?  I feel extremely inefficient when I don't have these
> three features..
>

BTW, if you're developing for windows, you may also want to check out
IronPython which plugs into the Visual Studio framework, I believe:

http://www.codeplex.com/IronPython
http://www.codeplex.com/IronPythonStudio
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2d graphics - what module to use?

2008-07-25 Thread arsyed
On Fri, Jul 25, 2008 at 2:13 AM, Pierre Dagenais <[EMAIL PROTECTED]> wrote:
> What is the easiest way to draw to a window? I'd like to draw something
>  like sine waves from a mathematical equation.
> Newbie to python.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I'd recommend matplotlib:

http://matplotlib.sourceforge.net/

Also see the "GUI" and "Plotting" sections on this page:

http://wiki.python.org/moin/UsefulModules
--
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamically adding methods to a class...

2008-07-29 Thread arsyed
On Tue, Jul 29, 2008 at 12:17 AM, Piyush Anonymous
<[EMAIL PROTECTED]> wrote:
> class MyObject:
>def __init__(self, name):
>  self.name = name
>
>def do_this_default(self):
>   print "default do_this implementation for %s" % self.name
>
> def custom_do_this(): #method to be added
>print "custom do_this implementation for %s" % self.name
>
>
> def funcToMethod(func,clas,method_name=None):
> """Adds func to class so it is an accessible method; use method_name to
> specify the name to be used for calling the method.
> The new method is accessible to any instance immediately."""
> import new
> method = new.instancemethod(func,None,clas)
> print method
> if not method_name: method_name=func.__name__
> clas.__dict__[method_name]=func
>
>
> myobj = MyObject('myobj1')
> funcToMethod(custom_do_this,MyObject) #trying 2 add method to class not
> instance
> print myobj.custom_do_this()
>
> ---
> Error I am getting;
> TypeError: custom_do_this() takes no arguments (1 given)
>
> Why am I getting it?
>

If your method is going to be bound to an instance, then it needs the
expected signature: the first parameter is always a reference to the
instance ("self").  Change it to "custom_do_this(self)" and it should
work.


> Also how can I do this in new style class (inherited from 'object')?
>
>

What did you try and how did it fail? This seems to work:

def foo(self):
print 'foo'

class Bar(object):
pass

Bar.foobar = new.instancemethod(foo, None, Bar)

b = Bar()
b.foobar()







>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Create 2D character matrix

2008-08-08 Thread arsyed
On Thu, Aug 7, 2008 at 1:36 PM, Simon Parker <[EMAIL PROTECTED]> wrote:
> Hello.
>
> I want to be able to create a 2D character matrix, ThisMatrix, like :
>
>
> a A
> b B
> c C
> d D
>
> and to be able to pick out elements, or rows or columns.
>
> I have become used to programming in R where I can easily refer to a row as
> :
>
> ThisMatrix [1,]
>
> and a column as
>
> ThisMatrix[,1].
>
> etc..
>
> Can this be done easily in Python ?
>
>

You can use numpy:

http://www.scipy.org/NumPy

for example:

In [139]: arr = numpy.char.array(['a', 'A', 'b', 'B', 'c', 'C'])

In [140]: arr = arr.reshape((3,2))

In [141]: arr
Out[141]:
chararray([['a', 'A'],
   ['b', 'B'],
   ['c', 'C']],
  dtype='|S1')

In [142]: arr[0,:]
Out[142]:
chararray(['a', 'A'],
  dtype='|S1')

In [143]: arr[:,0]
Out[143]:
chararray(['a', 'b', 'c'],
  dtype='|S1')

More documentation here:

http://mentat.za.net/numpy/refguide/

or take a look at these pages for some quick examples of what's possible:

http://pages.physics.cornell.edu/~myers/teaching/ComputationalMethods/python/arrays.html
http://www.scipy.org/Numpy_Example_List_With_Doc
--
http://mail.python.org/mailman/listinfo/python-list